This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes classes, help Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "classes, help" Watch "classes, help" New topic
Author

classes, help

Tim Tock
Greenhorn

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 ... , ...;
program1:
public String toString() {
stringA += "my name"+myname+"last name" + lastname;
return stringA
}
program2:
System.out.println(program1.lastname);
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:

Angel
[ January 15, 2004: Message edited by: Angel Dobbs-Sciortino ]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: classes, help
 
Similar Threads
Problems with Collection serialization
How can I call my obj in another program?
Accessibility Example from Khalid Mughal-getting compilation errors
pipe data through stdout in windows.
how to Import a program from another folder