Following lines are from K&B book,page no.128.(Constructor Chaining
We know that constructors are invoked at runtime when you say new on some class
type as follows:
Horse h = new Horse();
But what really happens when you say new Horse() ?
(Assume Horse extends Animal and Animal extends Object.)
1. Horse constructor is invoked. Every constructor invokes the constructor
of its superclass with an (implicit) call to super(), unless the constructor
invokes an overloaded constructor of the same class (more on that in a
2. Animal constructor is invoked (Animal is the superclass of Horse).
3. Object constructor is invoked (Object is the ultimate superclass of all
classes, so class Animal extends Object even though you don't actually
type "extends Object" into the Animal class declaration. It's implicit.) At
this point we're on the top of the stack.
4. Object instance variables are given their explicit values
Animal class constructor is implicitly called when we give a statement like:
Horse h=new Horse();
Animal class constructor in return will call Object class constructor which is its default parent class,means Object class constructor will implicity called by Animal class construtor.
Then why point 3 and 4(above mentioned) says that Object constructor is invoked and Object instance variables are given their explicit values
?we are not passing any value to Object class constructor from Horse class or Animal class.Explicit values are those which we pass to a constructor.But here which statement is passing explicit values?
Please clear my doubt.Thanks in Advance.