wood burning stoves*
The moose likes Java in General and the fly likes How to access private field and private method in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to access private field and private method in Java" Watch "How to access private field and private method in Java" New topic
Author

How to access private field and private method in Java

Ajit Aks Singh
Greenhorn

Joined: Apr 23, 2013
Posts: 1
Saif Asif
Ranch Hand

Joined: Aug 11, 2011
Posts: 440

Greeting Ajit,

Why have you declare the getters as private ? The conventions say that you declare public getters/setters to access/change the values of the private members. Sy by convention you have to declare the getter methods of class MyTL as



Edit :
You can use reflection to access the private methods but that is not the recommended way to get the job done since by reflection , you do explicitly change the access modifier of the private method to public and then call it.

Muhammad Saif Asif Mirza
OCJA(5/6) OCJP(6) OCJWCD(6)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to access private field and private method in Java
 
Similar Threads
Reflection got at field editing exception
Class.forName()
"private" access
element of the array from another class
can i use java to check the disk usage?