I've read in a book: "In Java a subclass collects automatically all visible properties of the superclass, but the objects in the hierarchy EXIST INDIVIDUALLY. This means: If a subclass is istantiated, the constructor automatically calls the constructor of the superclass to instantiate the upper object." I knew about the constructor-chaining but never thought about the consequences. This means: When creating one single object (not of the superclass Object) there are really some more objects created? If so: Could anyone post me a link or give me a hint where to find more of this subject? I haven't found anything telling me what exactly happens during runtime if a child-object is created.
Another question: whether a method should be dynamically invoked or static, this is decided by the compiler, am I seeing this right?
When you create an object of the derived class, it contains within it a subobject of the base class. This subobject is the same as if you had created an object of the base class by itself. It's just that from the outside, the subobject of the base class is wrapped within the derived-class object.
We would generally say there is one object created, because the "subobjects" are inseparable parts of the derived object. After all, whether we treat a reference to this object as the base type or the derived type, that reference still points to the same object.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Mar 29, 2007
In this case I am beginning to understand what really happens if an object inherits methods from a superclass.
Thanks for the answer and the link. Haven't heard about "Thinking in Java 3" yet. Seems to be an interesting ressource.