日期:2014-05-20 浏览次数:20858 次
public class InterfaceDemo { public static void main(String[] args) { MInterface[] ary=new MInterface[5]; ary[0]=new A(); ary[1]=new B(); ary[2]=new C(); ary[3]=new B(); ary[4]=new A();//接口的具体实现类 for(MInterface m:ary){ m.move();//java的自动向下绑定会自动实现具体实现类的move()方法 } } } class A implements MInterface{ @Override public void move() { //To change body of implemented methods use File | Settings | File Templates. System.out.println("这一行代表A对接口方法的业务逻辑实现"); } } class B implements MInterface{ @Override public void move() { //To change body of implemented methods use File | Settings | File Templates. System.out.println("这一行代表B对接口方法的业务逻辑实现"); } } class C implements MInterface{ @Override public void move() { //To change body of implemented methods use File | Settings | File Templates. System.out.println("这一行代表C对接口方法的业务逻辑实现"); } } interface MInterface{ public void move(); }