*
The moose likes Beginning Java and the fly likes How i can set a variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How i can set a variable " Watch "How i can set a variable " New topic
Author

How i can set a variable

Joig
Greenhorn

Joined: Oct 08, 2002
Posts: 5
hello,
How i can set a variable
Thanks
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Joig,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 984


Something like that?


Please ignore post, I have no idea what I am talking about.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Originally posted by Joig:
How i can set a variable


Depends on where you want to set it FROM. When you are inside the code of a class, and the variable is a class member, you can just set it as shown above.
If you are in another class and you want to set the value of a member variable for an instance that you hold a reference to you can use:
myVarHoldingYourClass.IamTheKing = 27;
Well, this is true if the variable is accessible. If it is private (like it probably SHOULD be) then you have to rely on the class having methods to set the value. The class holding the private variable would probable have a method named
setIamTheKing(int i);
and you would call it using
myVarHoldingYourClass.setIamTheKing(27);
Now if the variable happens to be static then it does not relate to any particular instance of the class, so you can just use the ClassName to get at the public variable:
YourClass.IamTheKing = 27;
Do we need to continue and talk about local variables, and using this to refer to the instance that we are in?


"JavaRanch, where the deer and the Certified play" - David O'Meara
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 984

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How i can set a variable
 
Similar Threads
Environment Variable
conditionally set Variable
setting classpath
Query on Custom Tags
can not run my web application get 404 error