class A {
public void doSomething(float f) {
//print "in A"
}
}
class B extends A {
public void doSomething(int i) {
// print "in B"
}
public static void main(String[] args) {
A a = new B();
a.doSomething(10);
}
}
The compiler first checks if doSomething() is present in class A. Once confirmed, during runtime, the object type is checked and the corresponding method is executed that is doSomething() of class B should be executed but doSomething() of class A is executed instead.
If both the methods would be the same then only class B doSomething() would be executed.
How does the compiler decide that a certain method is overridden and thus it will be taken care by the JVM?