WEB开发网
开发学院WEB开发Jsp 定义函数数组,跟一个外国哥们学来的:) 阅读

定义函数数组,跟一个外国哥们学来的:)

 2008-01-05 10:45:31 来源:WEB开发网   
核心提示:效 果: 屏幕上输出以下信息:你运行了函数 funcA你运行了函数 funcB你运行了函数 funcC 程序代码:interface FunctionArrayInterface // 定义接口,希望批量执行的函数用统一的名称定义在接口内{void runit();}class funcA implements Fun

  效 果: 屏幕上输出以下信息:
  你运行了函数 funcA
  你运行了函数 funcB
  你运行了函数 funcC
  程序代码:
  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();
  }
  }

Tags:定义 函数 数组

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接