Overridden Method Call in Superclass Constructor
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
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE