File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes classes, help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "classes, help" Watch "classes, help" New topic

classes, help

Tim Tock

Joined: Jan 15, 2004
Posts: 15
newbie here, hi all
Could someone show me how to read a variable from one class to another for example, i have a file called program1 and program 2, heres a snippet. In program2 I want to pull the value from program1 but the code doesnt seem to work, in program1 i have made the values public i.e. public int ... , ...;
public String toString() {
stringA += "my name"+myname+"last name" + lastname;
return stringA
Angel Dobbs-Sciortino
Ranch Hand

Joined: Sep 10, 2003
Posts: 101
Using program1.lastname goes against proper encapsulation. You should use a get method. Also, you need to instantiate an instance of your Program1 object. Here's some example code:

[ January 15, 2004: Message edited by: Angel Dobbs-Sciortino ]
I agree. Here's the link:
subject: classes, help
It's not a secret anymore!