还是需要理解一下的.
interface Animal
{
public abstract void eat();
}
class Dog implements Animal
{
public void eat()
{
System.out.println("eat dog");
}
}
class Test
{
public void show(Animal a) //Animal a = new Dog();
{
a.eat();
}
}
class AnimalTest
{
public static void main(String[] args)
{
Test t = new Test();
//Dog d = new Dog();
//t.show(d);
t.show(new Animal(){ // 匿名内部类
public void eat()
{
System.out.println("eat dog");
}
});
}
} |
|