--- ab.java ------------------------------------------------- public class ab { public int a; public int b; public ab(int x, int y){ a = x; b = y; } public ab() { a = 1; b = 1; } public int getA() { return a; } public void setA(int x) { a = x; } public int plus() { return a + b; } public void print() { System.out.println("a="+a+",b="+b); } } --- report.java ---------------------------------------------- import java.lang.reflect.*; public class report { public static void main(String argv[]){ Class cls; try { cls = Class.forName("ab"); } catch(Exception e){ System.out.println("cannot instantiate class"); return; } try { System.out.println("Field:"); Field fields[] = cls.getDeclaredFields(); for(int i = 0; i < fields.length; i++){ System.out.println(" "+fields[i].toString()); } } catch(Exception e){ System.out.println("exception!!!"); return; } } } ---- test.java --------------------------------------------- import java.lang.reflect.*; public class test { public static void main(String argv[]){ Class cls; Object obj; try { cls = Class.forName("ab"); } catch(Exception e){ System.out.println("cannot instantiate class:"+e); return; } try { Field a = cls.getField("a"); Field b = cls.getField("b"); Class pTypes1[] = { Integer.TYPE, Integer.TYPE }; Constructor Cons = cls.getConstructor(pTypes1); Class pTypes2[] = { Integer.TYPE }; Method setA = cls.getMethod("setA",pTypes2); Class pTypes3[] = { }; Method getA = cls.getMethod("getA",pTypes3); Method plus = cls.getMethod("plus",pTypes3); Method print = cls.getMethod("print",pTypes3); Object VOID[] = { }; Object args[] = { new Integer(20), new Integer(1) }; obj = Cons.newInstance(args); System.out.println("a="+a.getInt(obj)); System.out.println("b="+b.getInt(obj)); a.setInt(obj,10); print.invoke(obj,VOID); System.out.println("a="+a.getInt(obj)); System.out.println("b="+b.getInt(obj)); Object o = plus.invoke(obj,VOID); System.out.println("a+b="+((Integer)o)); } catch(Exception e){ System.out.println("exception!!! "+e); return; } } }