Please explain how to read this code so I can understand. What is output by the
ID: 3551880 • Letter: P
Question
Please explain how to read this code so I can understand.
What is output by the code below?
public class Cat{
private int x, y;
public Cat(){
x = y = 5;
}
public void fun(){
x = 7;
}
public double go(){
return x;
}
public void back(){
fun();
}
public String toString() {
return x + " " + y;
}
}
public class Lion extends Cat{
private int x;
public Lion(){
x = 9;
}
public void fun(){
x = 3;
}
public double go(){
return x;
}
public void back(){
super.back();
}
public String toString(){
return super.toString() + " " + x;
}
}
Cat fred = new Lion();
fred.fun();
fred.back();
System.out.println(fred);
A.
5 5 9
C.
5 5 3
B.
7 7 9
D.
9 5 9
Explanation / Answer
C.
5 5 3