Code
. Parent class.
public class Person {
public Person(){
}
public void dri(){
System.out.println("dri");
}
}
. Subclass.
public class Son extends Person {
public Son(){
super();
}
public void dri(){
System.out.println("dri");
}
public static void main(String[] args){
Person p=new Son();
p.dri();//:dri
}
}
question:
Person p=new Son (); the p reference here points to the real class new Son (); in the subclass. This should be the upward transformation. The upward transformation will lose the methods unique to the subclass. Why is it that instead of calling the dri () method in the parent class, the dir () method in the subclass is called instead? That"s weird