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
classA c = new classB();
or
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.
No comments:
Post a Comment