File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Accessing varaibles from another class. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Accessing varaibles from another class." Watch "Accessing varaibles from another class." New topic
Author

Accessing varaibles from another class.

Naf Rash
Ranch Hand

Joined: Feb 19, 2004
Posts: 85
Suppose that there are 2 separate classes. Is it possible to access some variable that is in a private method of the other class? If so could you please provide me an example of how this could be done?
Eddie Vanda
Ranch Hand

Joined: Mar 18, 2003
Posts: 281
Hi Naf,
You have a couple of problems.
Things are declared private so people cannot access it from any other classes.(not sure about extending though)
Method variables are stored on stack only while that method is running.


The nice thing about Standards is that there are so many to choose from!
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
Generally speaking... "No you can't". Private methods can't be accessed from any other class, except from the class they are located in (Even if they were subclassed).


However you should know that in the case of inner classes it will be a different story, see code:


- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. <br />- What truth? <br />- That there is no spoon!!!
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
As stated, the answer to your question is "no." However, if you describe what you want to do in more detail (perhaps with some code to illustrate), we may be able to suggest a solution that uses the tools that Java provides.
Layne


Java API Documentation
The Java Tutorial
 
Don't get me started about those stupid light bulbs.
 
subject: Accessing varaibles from another class.