How fields work in Polymorphism Java? [duplicate]
问题 This question already has answers here : Slight confusion regarding overriding where variables are concerned (6 answers) Closed 3 years ago . I was reading Interview Questions about java and found nice example and got confused. Because there is not well/more explanation that could help me to understand this example. Here is the example. public class MainClass { public static void main(String[] args) { Parent p = new Child(); System.out.println(p.getObject().x); } } class Parent { int x = 10;