import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;

public class MethodExecution {
	public static void main(String[] args) {
		test o1 = new test();

		try {
			Method helloMethod = (o1.getClass()).getMethod("hello", null);
			helloMethod.invoke(o1, null);

			Class[] formalParameters = { String.class };
			helloMethod = (o1.getClass()).getMethod("hello", formalParameters );
			Object[] argumentList = { "stranger" };
			helloMethod.invoke(o1, argumentList);
		} catch (NoSuchMethodException e) {
			System.out.println("A NoSuchMethodException occurred!\n"+e.toString()+"\n"+e.getMessage() );
			e.printStackTrace();
		} catch (IllegalAccessException e) 	{
			System.out.println("A NoSuchMethodException occurred!\n"+e.toString()+"\n"+e.getMessage() );
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			System.out.println("An InvocationTargetException occurred!\n"+e.toString()+"\n"+e.getMessage() );
			e.printStackTrace();
		} //catch
	} //main()
} //class MethodExecution

class Test {
	public void hello() {
		System.out.println("simple hello!");
	} //hello()

	public void hello(String name) {
		System.out.println("hello "+name);
	} //hello()
} //class Test