reflection_invoke_method.htm

import java.lang.reflect.*;
import java.io.*;
public class Test_this extends process_this{
static public void main( String[] args )throws IOException
{
try {
Class cls = Class.forName("process_this");
Class partypes[] = new Class[2];
partypes[0] = String.class;
partypes[1] = Integer.TYPE;
Method meth = cls.getMethod( "method_this", partypes);
process_this methobj = new process_this();
Object arglist[] = new Object[2];
arglist[0] = "Hello";
arglist[1] = new Integer(47);
//Object retobj = meth.invoke(methobj, arglist);
//Integer retval = (Integer)retobj;
System.out.println( meth.invoke(methobj, arglist));
}
catch (Throwable e) {
System.err.println(e);
}}}
class process_this
{
public String str= "manas";
private int n1 = 23;
public int n2 = 34;
public process_this(){ System.out.println("this is a blank constructor");}
public process_this(String str){ System.out.println("this is a string constructor");}
public process_this(String str, int n3){ System.out.println("this is a string integer constructor");}
protected process_this(String str1, String str2){ System.out.println("this is a string string constructor");}
public String method_this(String str2, int n4)throws IOException
{
double dd= 23.45;
String st = "received ";
st += str2;
System.out.println("method will do something later : "+ this.n1 + dd);
System.out.println("method will do something later : "+ st + ":" + n4);
return st;
}}