为什么我用记事本能编译出来,而用eclipse就编译出错?然而把Cat类名换成Cats就可以正常运行了。谢谢
public class DuoTai {public static void main(String[] args) {
// TODO Auto-generated method stub
Animal a1 = new Cat();
a1.eat();
Animal a2 = new Dog();
a2.eat();
}
}
class Animal {
public void eat(){
System.out.println("吃东西");
}
}
class Cat extends Animal {
public void eat(){
System.out.println("猫吃鱼");
}
}
class Dog extends Animal {
public void eat(){
System.out.println("狗吃肉");
}
}
错误类型
Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
Exception Details:
Location:
DuoTai.main([Ljava/lang/String;)V @9: invokevirtual
Reason:
Type 'Cat' (current frame, stack[0]) is not assignable to 'Animal'
Current Frame:
bci: @9
flags: { }
locals: { '[Ljava/lang/String;', 'Cat' }
stack: { 'Cat' }
Bytecode:
0x0000000: bb00 1059 b700 124c 2bb6 0013 bb00 1859
0x0000010: b700 1a4d 2cb6 0013 b1
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)