Superclass Method Call and Variable Shadowing
Consider the following class declarations. What is printed when the main method in the Derived class is executed?
class Base {
int num = 3;
String getInfo() { return "Base" + num; }
}
class Derived extends Base {
int num = 7;
String getInfo() { return super.getInfo() + (num * 2); }
public static void main(String[] args) {
Derived d = new Derived();
System.out.println(d.getInfo());
}
}
A
Base314
B
Compilation Error
C
Base37
D
Base3 14
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE