`

定义函数数组

    博客分类:
  • JAVA
 
阅读更多

interface FunctionArrayInterface // 定义接口,希望批量执行的函数用统一的名称定义在接口内
  {
  void runit();
  }
  
  class funcA implements FunctionArrayInterface // 函数A
  {
  public void runit()
  {
  System.out.println("你运行了函数 funcA");
  }
  }
  
  class funcB implements FunctionArrayInterface // 函数B
  {
  public void runit()
  {
  System.out.println("你运行了函数 funcB");
  }
  }
  
  class funcC implements FunctionArrayInterface // 函数C
  {
  public void runit()
  {
  System.out.println("你运行了函数 funcC");
  }
  }
  
  public class Untitled1
  {
  public static void main(String args[])
  {
  FunctionArrayInterface[] funcs = new FunctionArrayInterface[3]; // 利用数组进行批量处理 
  funcs[0] = new funcA();
  funcs[1] = new funcB();
  funcs[2] = new funcC();
  
  funcs[0].runit();
  funcs[1].runit();
  funcs[2].runit();
  }
  }
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics