Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 9: Inheritance
Start Practice TestPractice Test
About Exam
medium Solved by 2 students

Polymorphism and Method Overriding

Mark
< 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

AB

B

BA

C

Nothing is printed because the code does not compile.

D

B

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

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

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