Why can we not point the Parent class object using Child class Reference.
class Abc
{
public void Message()
{
System.out.println("Abc");
}
}
class pqr extends Abc
{
public void Message()
{
System.out.println("pqr");
}
}
class test1
{
public static void main (String [] ars)
{
Abc a = new Abc();
a.Message();
Abc b = new pqr();
b.Message();
pqr c = new pqr();
c.Message();
//pqr d = new Abc();
}
}
So My question is if Abc b = new pqr();
is possible then why not pqr d = new Abc()
;(As pqr is a child class and it will have all the features of parent class.)
I just wanted to check If I am doing d.Message()
what it will print whether parent class method or child class method.
Thanks