父类里面加个
abstract void abc();
因为d对象属于AbsDemo类型,调用d.abc()它会去AbsDemo类里面找这个方法,显然是找不到.
public class Demo2 {
public static void main(String[] args) {
A a = new B();
B b = new B();
a.a();
// a.b();//The method b() is undefined for the type A
}
}
abstract class A{
abstract void a();
}
class B extends A{
void a(){
System.out.println("B");
}
void b(){
System.out.println("b");
}
} |