接口与集体的实现类之间存在多态性


public class TestInterface {
	
	public static void main(String[] args) {
		Duam d = new Duam();
		
		TestInterface.test1(d);
		TestInterface.test2(d);
		TestInterface.test3(d);
	}
	
	public static void test1(Runner r){ //Ruuner r = new Duam();
		r.run();
	}
	
	public static void test2(Swimmer s){//Swimmer s = new Duam();
		s.swim();
	}
	
	public static void test3(Flier f) {//Flier f = new Duam();
		f.fly();
	}
}

interface Runner {
	public abstract void run();
}

interface Swimmer {
	public abstract void swim();
}

interface Flier {
	public abstract void fly();
}



本文转载:CSDN博客