Polymorphism and Method Overriding
Consider the following class declarations.
public class ClassA
{
public String getValue()
{
return "A";
}
public void showValue()
{
System.out.print(getValue());
}
}
public class ClassB extends ClassA
{
public String getValue()
{
return "B";
}
}
Assume the following code segment is executed in a method of a class other than ClassA or ClassB.
ClassA obj = new ClassB();
obj.showValue();
What is printed as a result of executing the code segment?
A
B
B
AB
C
Nothing is printed because the code does not compile.
D
BA
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE