|
| GAMES++ |
|
|
|
 |
|
| BROWSER UTILITIES |
|
|
|
 |
|
| AFFILIATES |
|
|
|
 |
|
| ADVERTISEMENT |
|
|
|
 |
|
Define An Array of Functions
Java: How To
public class testf
{
public static void main(String args[])
{
Command[] commands = new Command[3];
commands[0] = new aCommand();
commands[1] = new bCommand();
commands[2] = new cCommand();
commands[0].exec();
commands[1].exec();
commands[2].exec();
}
}
class aCommand implements Command
{
public void exec()
{
System.out.println("a");
}
}
class bCommand implements Command
{
public void exec()
{
System.out.println("b");
}
}
class cCommand implements Command
{
public void exec()
{
System.out.println("c");
}
}
interface Command
{
void exec();
}
|
|
|