Package COM. sadhu; import Java. util. *; import Java. lang. reflect. *;/***/public class sample {public static void main (string [] ARGs) throws exception {class Cl = Class. forname ("com. sadhu. reflecttest "); object RT = Cl. newinstance (); // create an object field [] field = Cl. getdeclaredfields (); For (field item: Field) {item. setaccessible (true); // if the value is true, it indicates that the reflected object should cancel the Java language access check during use. If the value is false, it indicates that the reflected object should perform Java access checks. If (item. getType () = string. class) {item. set (RT, "Zhang San");} If (item. getType () = int. class) {item. set (RT, 10);} system. out. println (item. get (RT); // output the value of the current field in the object }}} class reflecttest {private string name; private int age; Public void setname (string aname) {This. name = aname;} Public String getname () {return this. name;} public void setage (INT Aage) {This. age = Aage;} public int getage () {re Turn this. Age;} public reflecttest () {system. Out. println ("Call the parameter-free constructor! ") ;}}/** Output result: No parameter constructor is called! John 10 */