可以的,给你写个例子
interface Speak {
void speak();
}
class Cat implements Speak {
public void speak() { System.out.println("meow"); }
}
class Dog implements Speak {
public void speak() { System.out.println("woof"); }
}
class Bird implements Speak {
public void speak() { System.out.println("chirrup"); }
}
class test
{
public static void main(String[] args) {
Speak[] pets = new Speak[]{ new Cat(), new Dog(), new Bird() };
for(Speak pet : pets)
pet.speak();
}
}