Jules wrote:
Quickie from a newbie
How do I change the value of a variable, say var, of ClassA from a different
class, say ClassB?
Quick question, but a long, convoluted answer :).
The answer is "it depends". There are three factors that need to be
dealt with:
1) Is the variable a static (or class) variable, or is it an instance
(object) variable?
2) What is the variable's visibility?
3) Are ClassA and ClassB in the same package?
(There are potentially more than three if you're working in a
multithreaded environment, but as you said you're a newbie, I'll presume
not).
Look up "member visibility" in any convienent Java programming
reference. You first need to be certain that ClassB has the necessary
rights to modify a field (variable) in ClassA in the first place.
Once you've assured yourself that you have such rights, how you'll do
the assignment depends on wether or not the variable is static.
If the variable is static, use:
ClassA.var = somevalue;
If the variable is non-static, use:
instanceOfClassA.var = somevalue;
...where "instanceOfClassA" is a field that was generated by creating a
"new" instance of ClassA, ie:
ClassA instanceOfClassA = new ClassA();
HTH!
Brad BARCLAY
--
=-=-=-=-=-=-=-=-=
From the OS/2 WARP v4.5 Desktop of Brad BARCLAY.
The jSyncManager Project:
http://www.jsyncmanager.org