Method Overriding and Overloading
What is printed when the following code is executed?
class Parent {
void foo(int a) { System.out.print("Parent int "); }
void foo(double a) { System.out.print("Parent double "); }
}
class Child extends Parent {
void foo(int a) { System.out.print("Child int "); }
}
public class Main {
public static void main(String[] args) {
Parent obj = new Child();
obj.foo(5);
obj.foo(5.0);
}
}
A
Parent int Parent int
B
Child int Child int
C
Parent int Parent double
D
Child int Parent double
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE