What is the ordering of method invocation when you have an abstract class with method behaviour implemented and also when no behaviour is implemented?
Lets say my abstract class is called Abs and it has two subclasses, Sub1 and Sub2
In case 1, Abs contains the implementation code for method Meth1
public abstract class Abs{
public void Meth1(){
//Some code
}
}
In a completely different class i have the method:
MyMethod(Abs a){
a.Meth1();
}
where I pass either Sub1 or Sub2 as substitute for Abs
In case 2, Abs doesnt contain the implementation code (but Sub1 and Sub2 do)
public abstract class Abs{
public abstract void Meth1();
}
and i call the same:
MyMethod(Abs a){
a.Meth1();
}
after passing in either Sub1 or Sub2.
What is the ordering of the method calls in each case? Does it always go to the superclass Abs and then to the subclass? Does it go to the subclass first, because the sublclass was passed in as the parameter, then the JVM checks whether there is implementation code provided in the subclass and if not, then the superclass method is called if there is implementation code?