Question: Consider the following class definitions. publ ic class ClassA { publ ic St r ing getValue ( ) { return A ; }

Consider the following class definitions.
publ ic class ClassA
{
publ ic St r ing getValue()
{
return "A";
}
publ ic void showValue()
{
System.out .pr int (getValue()) ;
}
}
publ ic class ClassB extends ClassA
{
publ ic St r ing getValue()
{
return "B";
}
}
The following code segment appears in a class other than ClassA or ClassB.
ClassA obj = new ClassB() ;
obj .showValue() ;
What, if anything, is printed when the code segment is executed?
(A) A
(B) B
(C) AB
(D) BA
(E) Nothing is printed because the code does not compile

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!