Consider the following Java program:
class A { int x = 1;; int getX() { return x; } void setX(int x) { this.x = x; } } class B extends A { int x = 2, y = 3; int getX() { return x; } void setX(int x) { this.x = x; } int getY() { return y; } void setY(int y) { this.y = y; } } class C extends B { int y = 5; int getY() { return y; } void setY(int y) { this.y = y; } } class RP30_1 { public static void main(String[] args) { C c = new C(); A a = c; System.out.println(a.x); System.out.println(c.x); System.out.println(c.y); System.out.println(((C)a).x); System.out.println(((B)a).x); System.out.println(((A)c).x); System.out.println(((B)c).x); System.out.println(((B)c).y); System.out.println(); System.out.println(a.getX()); System.out.println(c.getX()); System.out.println(c.getY()); System.out.println(((C)a).getX()); System.out.println(((B)a).getX()); System.out.println(((A)c).getX()); System.out.println(((B)c).getX()); System.out.println(((B)c).getY()); } } |
What is the output of this program?