Method Overriding And Increment Operators
What does the program print when executed?
class Number {
int x = 10;
int update() { return x++; }
}
class SubNumber extends Number {
int update() { return ++x + super.update(); }
public static void main(String[] args) {
SubNumber sn = new SubNumber();
System.out.println(sn.update());
}
}
A
21
B
20
C
Compilation Error
D
22
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE