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

Static Method Hiding Instance Method

Mark
< Prev
Next >

Given the following class declarations, what is the result of an attempt to compile and execute the main method in the Child class?

class Parent {
    public void display() {
        System.out.print("Parent ");
    }
}

class Child extends Parent {
    public static void display() {
        System.out.print("Child ");
    }
    
    public static void main(String[] args) {
        Parent p = new Child();
        p.display();
    }
}
A

No output

B

Compilation Error due to static method hiding an instance method

C

Child

D

Parent Child

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|