Given: What is the reference type of myZ and what is the type of the object it references?
A.
Reference type is X; object type is Z.
B.
Reference type is Z; object type is Y.
C.
Reference type is Z; object type is Z.
D.
Reference type is Y; object type is Y.
B
Answer: B
Explanation:
Reference type is Z because varaible myZ is of type Z.
Object type is Y, because myZ = myX, myX = myY and myY = new Y();
Answer: D
Code question:
public interface Z {
}
public class X implements Z{
public String toString() {
return “I am X”; }
public static void main(String[] args) {
Y myY = new Y();
X myX = myY;
Z myZ = myX;
System.out.println(myZ + ” \n”+ myZ.getClass());
}
}
public class Y extends X {
@Override
public String toString() {
return “I am Y”;
}
}
Output:
I am Y
class Y