class Zoo
{
private class Tiger implements Animal
{
public void eat()
{
System.out.println("tiger eat");
}
public void sleep()
{
System.out.println("tiger sleep");
}
}
Animal getAnimal()//这里不明白,Animal不是接口么,怎么可以定义方法?
{
return new Animal()//还有这里,接口不是不能实例化么??
{
public void eat()
{
System.out.println("animal eat");
}
public void sleep()
{
System.out.println("animal sleep");
}
};
}
}
class Test
{
public static void main(String[] args)
{
Zoo z=new Zoo();
Animal an=z.getAnimal();
an.eat();
an.sleep();
}
}
interface Animal
{
void eat();
void sleep();
}
呼如林
元芳怎么了
慕无忌1623718
守着一只汪