Hi,
Help in understanding the below given code.
class Super{
private void display(){
System.out.println("Super display");
}
public static void main(
String arg[]){
Super s = new Sub();
s.display();
}
}
class Sub extends Super{
public void display(){
System.out.println("Sub display");
}
}
I expected the output to be "Sub display", as the object type of S is Sub and hence the method belonging to Sub class should be executed. Is it that the virtual machine will look into the object type only in case if the corresponding method is overridden?
Regards
Yuvi