use this
package com.sample;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class ReflectionAPIOne {
public static void main(String[] args) throws NoSuchMethodException,
SecurityException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException {
String x = "sample";
// Method method = ReflectionAPI.class.getMethod(x, String.class);
Method method = ReflectionAPIOne.class.getMethod(x, String.class);
method.invoke(method, "age");
System.out.println("End");
}
public static void sample(String a) {
System.out.println("in test " + a);
}
}