Method Overriding with Super Keyword
What does the program print when executed?
class Greeting {
String sayHello() { return "Hello"; }
}
class PersonalizedGreeting extends Greeting {
String name = "Alice";
String sayHello() { return super.sayHello() + ", " + name; }
public static void main(String[] args) {
System.out.println(new PersonalizedGreeting().sayHello());
}
}
A
Compilation Error
B
HelloAlice
C
Hello, Alice
D
Alice
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE