|
|
//for example only
class A
{}
class B extends A
{
public static void main (String [] args)
{
A a1 = new A();
A a2 = new B(); //my doubt lies here
System.out.println(a1);
System.out.println(a2);
}
}When it is declared as "A a1 = new A();", object is created to class A and 'a1' refers to the newly created object.
But, when it is declared as "A a2 = new B();", what does it imply? I am confused why should a class B object be referred by reference variable of A ?
I request to help me making this concept clear, please.