Subclass – Arguments From Superclass

There’s no magic happening! __init__ methods work just like all others. You need to explicitly take all the arguments you need in the subclass initialiser, and pass them through to the superclass. class Superclass(object): def __init__(self, arg1, arg2, arg3): #Initialise some variables #Call some methods class Subclass(Superclass): def __init__(self, subclass_arg1, *args, **kwargs): super(Subclass, self).__init__(*args, **kwargs) … Read more

C#: interface inheritance getters/setters

Method hiding in an interface isn’t nearly as grungy; I’d go with something like: interface IBasicProps { int Priority { get; } string Name {get;} //… whatever } interface IBasicPropsWriteable:IBasicProps { new int Priority { get; set; } new string Name { get; set; } //… whatever } class Foo : IBasicPropsWriteable { public int … Read more

Is synchronized inherited in Java?

No, you will always have to write synchronized. If you call the synchronized method of the super class this will of course be a synchronized call. synchronized is not part of the method signature. See http://gee.cs.oswego.edu/dl/cpj/mechanics.html for detailed description from Doug Lea, Java threading boss (or so).

Multiple Inheritance Ambiguity with Interface

The diamond problem only applies to implementation inheritance (extends in all versions of Java prior to Java 8). It doesn’t apply to API inheritance (implements in all versions of Java prior to Java 8). Since interface methods with matching type signatures are compatible, there is no diamond problem if you inherit the same method signature … Read more

Is there a way to guarantee an interface extends a class in Java?

Java interfaces cannot extend classes, which makes sense since classes contain implementation details that cannot be specified within an interface.. The proper way to deal with this problem is to separate interface from implementation completely by turning Vehicle into an interface as well. The Car e.t.c. can extend the Vehicle interface to force the programmer … Read more

In C# 4.0, is it possible to derive a class from a generic type parameter?

Generic types in C# are not C++ templates; remember, a generic type must work for all possible type arguments. A template need only work for the constructions you actually make. This question is a duplicate; see my answer to Why cannot C# generics derive from one of the generic type parameters like they can in … Read more