How to make any private field/method public in java

Posted on

From the start of java studying we now have been taught concerning the scope of personal fields/strategies in java however regardless of the actual fact about personal fields/strategies accessibility exterior the category, its achievable utilizing java’s reflection library. So let’s at present focus on how we are able to obtain this utilizing reflection.

Let’s consisted following class comprise one personal area and one personal technique.

The above class has a way computeMsgLength() which is personal to the category. Now if we wish to entry this technique out website of the category/package deal then we have to use java reflection api.

To make any area/technique accessible from exterior its scope, use setAccessiable() technique of Subject/Technique class.

Supply techzoo.org