Hi,
Are you refer to the pointer to function used in C?
This may not be the correct approach but it may offer something close to what you are looking for:
public class Test
{
public static void main(String[] arg)
{
Common c = null;
if(arg[0].equals("0"))
{
c = new Add();
}
else
c= new Sub();
Test tt= new Test();
tt.test(c,2,1);
}
public void test(Common c, int a, int b)
{
System.out.println(c.function(a,b));
}
}
interface Common
{
public int function(int a, int b);
}
class Add implements Common
{//this is the add function
public int function(int a, int b)
{
return a+b;
}
}
class Sub implements Common
{
public int function(int a, int b)
{
return a-b;
}
}