When a class extends another class, the subclass constructor calls the super class constructor.
In this process there are 2 objects created, sub class and super class. My Question is what happens to this super class object through out the life cycle of subclass object?
Will it be garbage collected as the reference is of sub class?
class A
{
public A()
{
System.out.println("super class constructor");
}
}
class B extends A
{
public B()
{
// super(); default added
System.out.println("sub class constructor");
}
}
class Test
{
public static void main(String[] args)
{
B ob=new B();
}
}