just working on this a little, just for checking it out, i made the following code which works fine( and that is scary):
so, building on this, i dared to venture further and put the two classes in two different packages. here is the code:
and the other class in the package "one" is:
this also works fine. but if i change the access modifier of the class one.TryReflect_1_1, then i get the following runtime exception:
Exception in thread "main" java.lang.IllegalAccessException: Class TryReflect_1
can not access a member of class one.TryReflect_1_1 with modifiers ""
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:57)
at java.lang.Class.newInstance0(Class.java:302)
at java.lang.Class.newInstance(Class.java:261)
at TryReflect_1.main(TryReflect_1.java:16)
yes, one.TryReflect_1_1 has no access modifier which means it is accessible only in the same class, but doing this
Object obj = Class.forName("one.TryReflect_1_1").newInstance();
does not cause an exception, there should be a way of running the above code as well???