I have the following 2 classes
public class classA {
classA() {
System.out.println("A");
}
}
class classB extends classA {
classB() {
System.out.println("B");
}
}
and then running
1
classA c = new classB();
or
2
classB c = new classB();
always gives
A
B
Why is this happening? At first glance, in either scenario, I would assume that only the classB
constructor would be called and thus the only output would be
B
but this is clearly wrong.