Posts

Showing posts from October, 2013

How to call private method of a class using Java in NetBeansIDE

Image
Steps: 1. Open NetBeansIDE. 2. In your project make a class file. 3. In your class file make a class, say 'C' with a private method. 4. Make another class say 'Calling' and write the following code in it:     public static void main(String[] args)throws Exception {                 Class c=C.class;         Object obj=c.newInstance();         Method m=c.getDeclaredMethod("msg", null);         m.setAccessible(true);         m.invoke(obj, null);             } 5. Run the file. 6. Finish. Thank You :)