it is possible that the code of A.foo is executed during evaluation of (new B{}).foo{} in the following?
Class A{
Public foo(){…}
}
Class B extends A {
Public foo(){…}
}
yes or no?
Class A{
Public foo(){…}
}
Class B extends A {
Public foo(){…}
}
yes or no?
public A(){
System.out.println("A constructor");
}
public void foo() {
System.out.println("A");
}
}class Test extends A {
public void foo() {
System.out.println("B");
}
public static void main(String[] args) {
new Test().foo();
}
}
不然的话,就被重写掉了,不会调用父类的
这里回答的各不相同,谁能确定答案?
你的题目是问有没有可能,那就是有可能的
如不显示调用会掉用父类的默认构造器