证明接口变量可以存储实现接口的类的对象的引用
/*时代Java - N o w J a v a . c o m 提供*/ interface Swimmable { void swim(); } class Fish implements Swimmable { private String name; public Fish(String name) { this.name = name; } public void swim() { System.out.println(name + " (a fish) is swimming."); } } public class Main { public static void main(String[] args) { Swimmable finny = new Fish("Finny"); finny.swim();/**来自 N o w J a v a . c o m**/ } }