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

王朝other·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

效 果: 屏幕上输出以下信息:

你运行了函数 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();

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航