| preferred AP College board partner for AP classes
AP Computer Science A/Unit 9: Inheritance
Start Practice Test
Share
medium Solved by 2 students
Polymorphism and Method Overriding
< Prev
Next >

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

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Not enough data yet to show leaderboard.

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy