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

Published: 15 October 2013
on channel: 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


Watch video How to call private method of a class using Java in NetBeansIDE online without registration, duration hours minute second in high quality. This video was added by user raksrahul 15 October 2013, don't forget to share it with your friends and acquaintances, it has been viewed on our site 4,196 once and liked it 4 people.