interface Animal
{
public abstract void eat();
}
class Animal2 implements Animal//建立一个Animal的子类,为后面传参
{
public void eat()
{
System.out.println("chi ba ");
}
}
class Test
{
public void print(Animal a)
{
a.eat();
}
}
class AnimalTest
{
public static void main(String[] args)
{
Test t =new Test();
Animal2 an = new Animal2();
t.print(an);
}
} |
|