Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
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

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

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