| preferred AP College board partner for AP classes
AP Computer Science A/Unit 9: Inheritance
Start Practice TestPractice Test
About Exam
hard
Overridden Method Call in Superclass Constructor
< Prev
Next >

What is the output when a new B() is instantiated in the above code?

class A {
    A() { overrideMe(); }
    void overrideMe() { System.out.println("A"); }
}

class B extends A {
    int x = 5;
    B() { }
    @Override
    void overrideMe() { System.out.println("B: " + x); }
}

public class Main {
    public static void main(String[] args) { new B(); }
}
A

Compilation Error

B

B: 5

C

B: 0

D

A

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