Method Overriding And Increment Operators
What is printed when the following program is 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
22
B
20
C
Compilation Error
D
21
Question Leaderboard
Not enough data yet to show leaderboard.
