Say that I have a super class and a sub class like below.
class Super {
public void action( ) {
System.out.println( “Super’s action” );
}
}
class Sub extends Super( ) {
public void action( ) {
System.out.println( “Sub’s action” );
}
}
In the main method I call this.
Super s1 = new Super( );
s1.action( );
Super s2 = new Sub( );
s2.action( );
Sub s3 = new Sub( );
s3.action( );
I know that the output will be
Super’s action
Sub’s action
Sub’s action
I've learnt that in the constructor, the first word is the static class type and the part with the () is the dynamic class. I know that the method lookup will always begin in the dynamic class so what I want to know is, what is the difference between s2 and s3? i.e Having the static class be of the parent type, or the static class be it's own type