最近学习java抽象类和接口,运行书上的例题,出现报错,
No enclosing instance of type Test is accessible. Must qualify the allocation with an enclosing instance of type Test (e.g. x.new A() where x is an instance of Test).
接口:
public interface Edible {
public abstract String howToEat();
}
测试类:
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Object[]object={new Tiger(),new Chicken(),new Apple(),new Orange()};
}
class Animal{
}
class Chicken extends Animal implements Edible{
public String howToEat(){
return "Chicken:Fry it";
}
}
class Tiger extends Animal{
public String howToEat(){
return "Chicken:Fry it";
}
}
abstract class Fruit implements Edible{}
class Apple extends Fruit{
public String howToEat(){
return "Apple:Make apple cider";
}
}
class Orange extends Fruit{
public String howToEat(){
return "Orange:Make orange juice";
}
}
}