I have done some research but I am no able to find why runtime polymorphism is not taking place in example below. According to my understanding foo(int a) should have been called in child.But out put is "Parent with long".Can someone throw light on this?
class Parent {
public void foo() throws RuntimeException {
System.out.println("Parent with no Parameter");
}
public void foo(long a) {
System.out.println("Parent with long");
}
}
class Child extends Parent {
public void foo() {
System.out.println("Child with no parameter");
}
public void foo(int a) throws RuntimeException {
System.out.println("Child with int");
}
}
class Demo {
public static void main(String... args) {
Parent p = new Child();
int a = 10;
p.foo(a);
}
}
Output:
Parent with long