I have a parent class A, and its child B. Both are having doSomething
method with diff type of parameters.
Class A
package Inheritance;
When you are using a reference of type A, you see only the methods defined for class A. Since doSomething
in B doesn't override doSomething
in A (since it has a different signature), it is not called.
If you were to use a reference of type B, both methods would be available, and doSomething
of B would be chosen, since it has a more specific argument (String vs Object).