import java.lang.reflect.*;
import java.io.*;
import java.lang.*;
public class Test_this extends process_this{
static public void main( String[] args )throws IOException
{
try {
Class cls = Class.forName("process_this");
System.out.println("--aletering the value of a pubic field");
Field fld_int = cls.getField("n2");
process_this change_values = new process_this();
System.out.println("\torignal n2 = " + change_values.n2);
//fld.setDouble(change_values, 123.34);
fld_int.setInt(change_values, 56);
System.out.println("\tchanged n2 = " + change_values.n2);
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);
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
{
String st = "received ";
st += str2;
System.out.println("method will do something about n2 : "+ n2);
System.out.println("method will do something later : "+ this.n1 + n2);
System.out.println("values of st and n4 are : "+ st + ":" + n4);
return st;
}
}