Hi Mukhan,
To access instance variable and instance method we need an object of that class.And whenever we create a object,constructor of that class is called.Any constructor implicity calls Parent class constructor through super(); statement.Which in return calls to its superparent class.
For example if we inherit class Animal in class Horse the inheritance tree will be like:
Object-->Animal-->Horse;
class Animal {
Animal(){
//super();
}
}
class Horse extends Animal
{
Horse(){
super(); //calls super class constructor
}
public static void main(
String[] ar)
{
Horse d=new Horse(); //calls constructor
}
}
So when ever you will make Horse class object it will call constructor of Horse class,which in return will call Animal class Constructor,whether you supply one or not compliler will implcitly add one statement like super(); to invoke animal class constructor.And Animal class constructor will call Object class constructor.
First Object class constructor completes that Animal class constructor completes and then atlast Horse class constructor completes.When the horse class constructor completes than only object is created.And with the help of that object we access instance variable and instance method.So we conclusion is to access a object we need instance of a class And to create instance we need constructor,and construtor implicitly class parent class constructor.
Therefore
That's because you cannot invoke an instance (in other words, nonstatic)
method (or access an instance variable) until after the super constructor has run.
Priya
---------
SCJP(preparing);