How can I accomplish the equivalent of function pointers in Java, for instance, for use in an array?
Ans : To treat executable code as an assignable, run-time swappable unit, you need to package it in a (small) class; the inner class facility added to the Java language starting with the JDK 1.1 simplifies this work. In the Java language, the smallest unit of code that you can treat in an object-like fashion is the class. (“The quanta of behavior are classes,” is James Gosling’s terser version of this idea.) To encapsulate code so that you can assign it to variables, pass it from object to object, and so on, you need to create one or more classes to contain the code. You can use either an interface or a simple superclass as the type for the code objects you want to manipulate. The following sample code shows one simple way to accomplish this, within the JDK 1.0.2 Java language: interface DoIt { public void doIt(); } class PrintMonth implements DoIt { public void doIt() { String[] monthNames = {“January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “Octob