class X { int a; X(int i) { a = i; } } class Y extends X { int b; Y(int i, int j) { super(j); b = i; } } class NadPodRef { public static void main(String args[]) { X x = new X(100); X x2; Y y = new Y(15, 25); x2 = x; // spravne prirazeno System.out.println("x2.a: " + x2.a); x2 = y; // take mozno priradit System.out.println("x2.a: " + x2.a); x2.a = 22; // OK // x2.b = 21; // Chybne X nema prvek b } }