+ 1

I have a question on Java, why the answer is A not D?

class X { int x1, x2, x3; } class Y extends X { int y1; Y() { x1 = 1;x2 = 2;y1 = 10; }} class Z extends Y { int z1; Z() { x1 = 3;y1 = 20;z1 = 100; }} public class Test3 { public static void main(String[] args) { Z obj = new Z(); System.out.println(obj.x3 + ", " + obj.y1 + ", " + obj.z1); } } Which constructor initlalizes the variable x3? A) only the default constructor of class X B) only the no-argument constructor of class Y C) only the no-argument constructor of class Z D) only the default constructor of object class (The Ans is A)

8th May 2017, 4:04 PM
黃冠融
黃冠融 - avatar
1 Odpowiedź
0
X is the most extended superclass what contain x3.
8th May 2017, 4:20 PM
Szabó Gábor
Szabó Gábor - avatar