Do subclasses inherit private fields?

Most of the confusion in the question/answers here surrounds the definition of Inheritance. Obviously, as @DigitalRoss explains an OBJECT of a subclass must contain its superclass’s private fields. As he states, having no access to a private member doesn’t mean its not there. However. This is different than the notion of inheritance for a class. … Read more

Are static methods inherited in Java?

All methods that are accessible are inherited by subclasses. From the Sun Java Tutorials: A subclass inherits all of the public and protected members of its parent, no matter what package the subclass is in. If the subclass is in the same package as its parent, it also inherits the package-private members of the parent. … Read more

Calling parent class __init__ with multiple inheritance, what’s the right way?

The answer to your question depends on one very important aspect: Are your base classes designed for multiple inheritance? There are 3 different scenarios: The base classes are unrelated, standalone classes. If your base classes are separate entities that are capable of functioning independently and they don’t know each other, they’re not designed for multiple … Read more

When to use an interface instead of an abstract class and vice versa?

I wrote an article about that: Abstract classes and interfaces Summarizing: When we talk about abstract classes we are defining characteristics of an object type; specifying what an object is. When we talk about an interface and define capabilities that we promise to provide, we are talking about establishing a contract about what the object … Read more

Is there a way to instantiate objects from a string holding their class name?

Nope, there is none, unless you do the mapping yourself. C++ has no mechanism to create objects whose types are determined at runtime. You can use a map to do that mapping yourself, though: template<typename T> Base * createInstance() { return new T; } typedef std::map<std::string, Base*(*)()> map_type; map_type map; map[“DerivedA”] = &createInstance<DerivedA>; map[“DerivedB”] = … Read more