Method Overriding With Super Keyword
Consider the following class definitions. What is printed as a result of executing the main method in the Test class?
class Base {
public String greet() {
return "Hello from Base";
}
}
class Derived extends Base {
@Override
public String greet() {
return super.greet() + " and Derived";
}
}
public class Test {
public static void main(String[] args) {
Derived d = new Derived();
System.out.println(d.greet());
}
}
A
Hello from Base
B
and Derived
C
Hello from Base and Derived
D
Compilation Error
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE