public class interfaceDemo {
public static void main(String [] args){
Eater a = new Eater();
a.eat(Jing8);
}
}
abstract class Animal{
abstract public void cry();
}
class Doy extends Animal{
public void cry(){
System.out.println("汪汪汪,,,");
}
}
class Jing8 extends Doy implements Eatable{
public void eat(){
System.out.println("香肉好好吃!");
}
}
interface Eatable{
public void eat();
}
class Eater{
public void eat (Eatable p){
System.out.println("食物准备就绪!");
p.eat();
}
}
为什么我调用JIng8的时候,显示出错,a.eat(JIng8);这个语句,Jing8显示出错,怎么改
你没传对象啊,Jin8是类名,应该传一个对象进去,如new Jin8()
时刻要记得,对象.属性,对象.方法,你得有对象才能点出来,你这里要先有Jing8的对象才能点他的方法,先new一下吧