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
hard

Inheritance and Private Method Behavior

Mark
< Prev
Next >

Consider the following class definitions.

public class Parent {
    public String identify() {
        return "Parent";
    }
    public void printIdentity() {
        System.out.print(identify());
    }
}

public class Child extends Parent {
    private String identify() {
        return "Child";
    }
}

The following code segment appears in a class other than Parent or Child.

Parent obj = new Child();
obj.printIdentity();

What is printed when this code segment is executed?

A

Child

B

Nothing is printed because the code does not compile.

C

Parent
Child

D

Parent

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|