Hi
I have seen the following code snippet in a site
Code:
class Parent {
String message = "parent";
}
class Child extends Parent {
String message = "child";
}
public class
Test {
public static void main(String[] args) {
Parent yo = new Child();
System.out.println(yo.message);
}
}
ans:Parent
I expected that it would print as "Child" because i thought that the object "yo" is the reference of Child(bacause of new Child ();)
Can anyone explain me