Good. Release, in turn, through your code.
Your first statement in your "foo" method
super.foo();
It is good that the explicit call to the superclass method foo . What is:
void foo() { System.out.println("Super"); }
Thus, "Super" is displayed on the console because you explicitly called this method using the super keyword. super refers to the superclass of the class, in the same way that this refers to the current class.
Next is the rest of the foo method in a subclass:
void foo() { super.foo(); System.out.println("Sub"); }
Well, after super.foo() is called, it's time to move on to the next statement that prints "Sub".
The reason your program goes to the subclass method first rather than the superclass is because of a principle called Polymorphism . That is, a subclass takes a method from a superclass and changes its behavior.
Abstract classes
You cannot instantiate abstract classes, but, but with the super keyword, you can still access the functionality of the superclass.
In the context of a Java virtual machine
So, what happens when you call a method call, the Java virtual machine will look for the method in the local class, if it is an instance method. If he cannot find him, he will move to the superclass. When you use the Polymorphism principle, the JVM finds a method with the correct signature in the subclass and stops looking. This is how inheritance and Polymorphism work in simple terms in the context of Java.
When overriding a method, you add a method with the same method signature (name, number and type of method fields) to the subclass definition. So the JVM finds this, and an overridden method is stored here.