class ClassInheritance { public static void main(String s[]) { A a = new A(); a.i = 4; B b = new B(); b.i = 10; // LINE X b.j = 20;
System.out.println("i = " + a.i); } }
class A { int i; }
class B // LINE Y { int j; }
Compilation Error at LINE Y - since class B is not extending class A
i = 4
i = 10
Compilation Error at LINE X - since the member variable i is not accessible in b's object
Correct Answer : D
The program throws a compilation error at LINE X, since the class B does not have the variable i, so the statement b.i raises a compilation error.
So, the answer is D.