Method Overriding and Super Keyword
Consider the following class declarations.
class Alpha {
int a = 2;
int multiply() { return a * 3; }
}
class Beta extends Alpha {
int a = 4;
int multiply() { return super.multiply() + a; }
public static void main(String[] args) {
System.out.println(new Beta().multiply());
}
}
What is printed when the program is executed?
A
6
B
10
C
Compilation Error
D
8
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE