Which constructor initializes the variable x3?

Given: Which constructor initializes the variable x3?

Given: Which constructor initializes the variable x3?

A.
Only the default constructor of class X

B.
Only the default constructor of object class

C.
Only the no-argument constructor of class Y

D.
Only the no-argument constructor of class Z

Explanation:



Leave a Reply 1

Your email address will not be published. Required fields are marked *


renko

renko

Answer: A

Code question:
public class Test3 {

public static void main(String[] args) {
Z obj = new Z();
System.out.println(obj.x3 +” “+ obj.y1 +” “+ obj.z1);
}

}
public class X {
int x1, x2, x3;
}
public class Y extends X {
int y1;
Y() {
x1 = 1;
x2 = 2;
y1 = 10;
}
}
public class Z extends Y{
int z1;
Z() {
x1 = 3;
y1 = 20;
z1 = 100;
}
}

Output:
0 20 100