How to call particular instances of 2 different classes from each other?

I have class1, and class2 (a GUI).

When the program is run, an instance of class2 is created, and then it itself creates an instance of class1 (which helps it perform tasks in the background). This enables class2 to call the methods of class1. However, how can class1 call the methods of this particular instance of class2, without creating another instance of it?

Thank You

[393 byte] By [what2097a] at [2007-10-2 15:50:25]
# 1

pass class2 in the constructor of class1.

public Class1 {

Class2 class2;

public Class1(Class2 class2) {

this.class2 = class2;

}

public void doXXX() {

....

this.class2.doYYY();

}

}

ordinary_guya at 2007-7-13 15:56:00 > top of Java-index,Java Essentials,New To Java...
# 2

Say I have a class3 and a class4 also.

Class1 has 'private static class3 class3Object = new class3();' in the constructor.

Can class4 invoke methods on class3Object?

Pressumably, class3Object would have to be made public, but even then, how can it be called from class1?

Thanks for the quick response!

what2097a at 2007-7-13 15:56:00 > top of Java-index,Java Essentials,New To Java...
# 3
Ah, I made class3Object public, and then invoked it from class4 using 'Class1.class3Object.method();'.Is there anyway to do this without making class3Object public however?Thanks
what2097a at 2007-7-13 15:56:00 > top of Java-index,Java Essentials,New To Java...
# 4
Create an accessor for the class3Object:public Class3 getClass3Object() { return class3Object;}Then:Class1.getClass3Object().method();
MLRona at 2007-7-13 15:56:00 > top of Java-index,Java Essentials,New To Java...