import java.lang.reflect.Method;
public class TestPrivate {
public static void main(String[] args) throws Exception {
Private p = new Private();
Class classType = p.getClass();
Object obj = classType.newInstance();
Method method = classType.getDeclaredMethod("echo",
new Class[] { String.class });
method.setAccessible(true);
Object value = method.invoke(obj, new Object[] { "Tom" });
System.out.println((String) value);
}
}
class Private {
private String echo(String message) {
return "Hello " + message;
}
}