+ 4
Is there a way in which we can access private variables of a class in java without setter and getter methods?
6 Réponses
+ 3
use reflection
+ 3
Even we can access the private constructor using reflection, I dont understand why did Java team designed something which is against security.
+ 2
@Jeremy Thanks for the answer but it's not correct.Let other put there comment on it.
+ 2
In order to access private fields, you need to get them from the class's declared fields and then make them accessible:Field.setAccessible(true); .Works for standalone java appilication.
+ 1
the whole point of declaring it private is so other classes have no access without getter and setter
0
no