Polymorphism and Method Overriding
What will be printed when the program is executed?
class A {
public String fun() { return "A"; }
public String fun(String s) { return s + "A"; }
}
class B extends A {
public String fun() { return "B"; }
public String fun(String s) { return s + fun(); }
}
public class Main {
public static void main(String[] args) {
A obj = new B();
System.out.println(obj.fun("Start"));
}
}
A
StartB
B
Compilation Error
C
BStart
D
StartA
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE