I have a basic question related to inheritance.
Consider the following code snippet:
public class B {
}
public class D extends class B{
public D(){
super();
}
public static void main(String args[]){
new D();
}
}
My question is whether new D() invocation will create 3 objects i.e. D, B, and top class Object or whether it will create only 1 object i.e. D?
I am confused as to whether inheritance leads to chained object creation or whether the compiler copies all the eligible public and protected members from the base class into the derived class so that base class does not need to be instantiated all the time.
When I see the bytecode, it looks like 3 objects are created because of init() invocations but I just wanted to be sure about it. I would appreciate if someone could comment on it.