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

Overridden Method Call in Superclass Constructor

Mark
< Prev
Next >

What is printed as a result of executing the following code segment?

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

A

B

B: 5

C

Compilation Error

D

B: 0

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|