class a{
public void foo(int a){
System.out.println("super");
}
}
class b extends a{
public void foo(int a){
System.out.println("sub");
}
}
And this is how I wrote my code to call it
a ob = new b();
ob.foo(7);
but it calls the subclass method ?
That’s the WHOLE POINT of overriding … so that when you call the method on an instance the subclass you get the subclasses override of the method!
On the other hand, the subclass itself can call the overridden version of the method in its superclass:
… which will print
if you call
fooon aBinstance.