I created 2 classes - Parentand Child, and so:
Parent.java
public class Parent {
String name = "Parent";
}
Child.java
public class Child extends Parent {
String name = "Child";
}
The Child class obscures the instance variable of the parent class name.
I created the main program as follows:
Test.java
public class Test {
public static void main(String[] args) {
Parent p = new Parent();
Child c = new Child();
System.out.println(p.name);
System.out.println(c.name);
Parent pc = new Child();
System.out.println(pc.name);
}
}
The output of the program is as follows:
Parent
Child
Parent
Now I do not understand when I try to access pc.name, then I get the output as Parentin accordance with the above output instead Child.
, pc Parent, Child . java , name, pc.name Child. , , .
, ?