Originally posted by Nabila Mohammad:
...Can you tell me why is it executing this way...
i dint get they Why part of the question...
Consider that a Subclass IS-A Superclass. So the first step in creating a Subclass is to create a Superclass, and then "extend" that Superclass to make it a Subclass.
First, we need the blueprint -- the class
itself. The Superclass class initializes first, with static variables and static initializers. When this is done, there is a fully initialized Superclass class to work with, and so the Subclass class can initialize its own static variables and static initializers.
After the class
(the blueprint) is fully initialized (from the top down), then we start creating the object.
Again, a Subclass IS-A Superclass, so we start by creating an instance of Superclass, initializing instance variables and executing non-static initializers. When this is done, the Superclass constructor can run (using initialized instance variables, if needed). At that point, there is a fully formed Superclass object to work with. The next step is to initialize the Subclass instance (instance variables and initializers), and finally execute the Subclass constructor.