Hello, according to the computation done my the MyBrain Quantum Computer somewhere in Europe, the following result should be displayed when using the printClasses method:
Jerry; - for obj
Mouse; - for mouse; obj being downcasted to mouse
GrayMouse; - for grayMouse as it was downcasted to GrayMouse from Mouse;
Jerry; for the final object.
Why the 4 Jerries for the correct solution?
public class Solution {
public static void main(String[] args) {
Object obj = new Jerry(); // Add your code here
Mouse mouse = (Mouse) obj;
GrayMouse grayMouse = (GrayMouse) mouse;
Jerry jerry = (Jerry) grayMouse;
printClasses(obj, mouse, grayMouse, jerry);
}
public static void printClasses(Object obj, Mouse mouse, GrayMouse grayMouse, Jerry jerry) {
System.out.println(jerry.getClass().getSimpleName());
System.out.println(grayMouse.getClass().getSimpleName());
System.out.println(mouse.getClass().getSimpleName());
System.out.println(obj.getClass().getSimpleName());
}
static class Mouse {
}
static class GrayMouse extends Mouse {
}
static class Jerry extends GrayMouse {
}
}