Polymorphism with instance variables [duplicate]
问题 This question already has answers here : Overriding member variables in Java ( Variable Hiding) (11 answers) Closed 6 years ago . Here are three classes that I wrote: public class Shape { public int x = 0; public void getArea() { System.out.println("I don't know my area!"); } public String toString() { return "I am a shape!"; } public int getX() { return x; } } public class Rectangle extends Shape { public int x = 1; public int getX() { return x; } public void getArea() { System.out.println(