Does an instance of superclass get created when we instantiate a particular class in java. If that is the case then there would be a lot of overhead of instantiating all the super classes. I tried following code:
public class AClass {
public AClass() {
System.out.println("Constructor A");
}
}
public class BClass extends AClass{
public BClass(){
System.out.println("Constructor B");
}
}
public class Test {
public static void main(String[] args) {
BClass b = new BClass();
}
}
The output of the code is :
Constructor A
Constructor B
So, does it mean that the complete hierarchy of the objects of the superclasses get created when we instantiate a class?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…