| preferred AP College board partner for AP classes
AP Computer Science A/Unit 9: Inheritance
Start Practice TestPractice Test
About Exam
medium Solved by 5 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

BA

B

B

C

AB

D

Nothing is printed because the code does not compile.

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.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

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