Inheritance and Private Method Behavior
Consider the following class definitions.
public class Parent {
public String identify() {
return "Parent";
}
public void printIdentity() {
System.out.print(identify());
}
}
public class Child extends Parent {
private String identify() {
return "Child";
}
}
The following code segment appears in a class other than Parent or Child.
Parent obj = new Child();
obj.printIdentity();
What is printed when this code segment is executed?
A
Child
B
Parent
Child
C
Nothing is printed because the code does not compile.
D
Parent
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE