| Refresh | Home EGTry.com

invoke a simple instance method dynamically


package reflection;

import java.lang.reflect.Method;

public class SimpleInstanceMethod {

	public static void main(String[] args) throws Exception {
		Class clazz=Class.forName("reflection.SimpleInstanceMethod");
		Object obj=clazz.newInstance();
		Method method1=clazz.getMethod("hello");
		method1.invoke(obj);
	}
	
	public void hello() {
		System.out.println("the instance hello() called");
	}
	


}