Can you imagine using a class without building its superclass first ? You have to build fundations before building a house. A superclass is like fundations. A superclass is so always created *before* its subclasses.
A subclass simply doesn't yet exist before superclass creation (contructor's call), so you can't really think of using its members.
In other words, the constructor call of a given class ensure that a new instance (or object) is ready to use.
For a given class, the compiler creates first an instance of its superclass then creates the instance of the class itself.
I hope this is clearer ;-)
Joined: Oct 11, 2004
Originally posted by Lionel Badiou: For a given class, the compiler creates first an instance of its superclass then creates the instance of the class itself.
Are you sure in this ....
What will happen when a class will extends abstract class ....
Joined: Jan 06, 2005
An abstract class is a class you declare abstract (can't be programmatically instancied). It's a convenient way to declare fundamental concepts of your OO design. Similarly, a constant is basically a variable that you can't programmaticaly change. But the compiler manage both as memory location.
If an abstract class contains variables/methods, the compiler allocates memory and do initalisation as normal instance creation, when you create an instance of its subclass.