public class A
{
private A(){
System.out.println("This is A");
}
} ..........................................................................................................................import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; public class Main {
public static void main(String[] args)
{
try
{
Class a = A.class;
Constructor c = a.getDeclaredConstructor((Class[])null);
c.setAccessible(true);
A obj = c.newInstance((Object[])null);
Method privateMethod = a.getDeclaredMethod("obj", (Class[])null);
privateMethod.setAccessible(true);
privateMethod.invoke(obj, (Object[])null);
}catch(Exception ex){
ex.getMessage();
}
}
}
No comments:
Post a Comment