Note: By convention,
Java class names begin with an uppercase letter, and variable names begin with a lowercase letter. So before I confuse myself, I'm going to use "ClassA" rather than "classA" here.
In fred's illustration, ClassA
HAS-A ClassB, which allows an instance of ClassB to be referenced within ClassA. That's the key. In his quick example, he created a
new instance of ClassB within ClassA -- and I think this is the part you're questioning. To fine-tune fred's HAS-A approach, you could use a constructor to pass a reference to an
existing ClassB into ClassA...
Or as fred just suggested above, you could use a setter method instead of a constructor.
Basically, you need to take a step back and look at your program as a whole -- considering how all the different pieces will need to interact. It might help to draw some diagrams of how everything relates, and based on that, decide
where to create the instances, and where to pass the references.
[ December 23, 2006: Message edited by: marc weber ]