// Inherit3: Variable shadowing // Originally by David Schwartz, dis@cs.cornell.edu // Modified by Kiri Wagstaff, wkiri@cs.cornell.edu class A { private int x = 1; public int getX() { return x; } } class B extends A { // This variable "shadows" A's variable x. public int x = 2; } public class Inherit3 { public static void main(String[] args) { B b = new B(); System.out.println(b.x); System.out.println(b.getX()); A a = new B(); System.out.println(a.getX()); } } /* output: */