| preferred AP College board partner for AP classes
AP Computer Science A/Unit 9: Inheritance
Start Practice TestPractice Test
About Exam
hard Solved by 1 students
Inheritance and Private Method Behavior
< 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

Parent
Child

C

Nothing is printed because the code does not compile.

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.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy