Considering the following:
class Parent {
public void print(Object s) {
System.out.println("I am inside Parent Object Method.");
}
}
public class Child extends Parent{
public void print(String s) {
System.out.println("I am inside Child String Method.");
}
public static void main(String arg[]) {
Parent a = new Child();
a.print(null);
}
}
Output:
I am inside Parent Object Method
Here JVM is calling Parent Method in place of child method regardless of the logic of "more specific method should be called" in ambiguity.
What would be the reason for this implementation in java?