If an instance of subclass is created, the output is sub0 sub2
Two questions on this:
Why is the subclass method called even though the superclass constructor is not finished?
Why is the instance field not initialized when called from the superclass constructor (the
sub0output)?
Example:
class Superclass{
int i = 1;
Superclass(){
aMethod();
}
void aMethod(){
System.out.println("super" + i);
}
}
class Subclass extends Superclass{
int i = 2;
Subclass(){
aMethod();
}
void aMethod(){
System.out.println("sub" + i);
}
}