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

Опубликовано: 15 Октябрь 2013
на канале: raksrahul
4,196
4

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

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 :)

#java #NetBeansIDE #programming #coding #developer #tips #tricks