I have a ClassA and ClassB. ClassB is inherited from ClassA. When I create an Object of ClassB it is Calling ClassB constructer, which is Fine. But Once the control goes to ClassB Constructer it is calling ClassA Constructer even if I don't call Explicitly by using Super() Keyword.
I learned that we need to use "Super()" keyword in the SubClass when we want to call Super Class Constructor.
But even with out calling Explicitely Super Class Constructer is being called.
Eg:
//Class A
Class ClassA {
public ClassA(){
//Constructor
//-> This is being called by ClassB Constructor with
out using Super Key Word.
}
}
//Class B
Class ClassB extends ClassB{
public ClassB(){
//Constructor
//-> Once the control comes here it is calling Super
Class Constructor.
}
public static void main(String[] args){
ClassB objClasB = new ClassB();
// -> Once this is done the control goes to Constructor
of this Class.
}
}
Can you pl explain . Thanks
I learned that we need to use "Super()" keyword in the SubClass when we want to call Super Class Constructor.
But even with out calling Explicitely Super Class Constructer is being called.
Eg:
//Class A
Class ClassA {
public ClassA(){
//Constructor
//-> This is being called by ClassB Constructor with
out using Super Key Word.
}
}
//Class B
Class ClassB extends ClassB{
public ClassB(){
//Constructor
//-> Once the control comes here it is calling Super
Class Constructor.
}
public static void main(String[] args){
ClassB objClasB = new ClassB();
// -> Once this is done the control goes to Constructor
of this Class.
}
}
Can you pl explain . Thanks