I have the following problem, and no idea how to solve it. Let's say we have a class classA, and in this class is the main method creating an object of the class itself. Now we take another class, classB. In the constructor of classA we make an object of classB. Now in a method of classB we want to call a method of classA.
Let me provide you with an example.
public class classA {
public classA() {
//some code
classB objectB = new classB();
}
public static void main(String[] args) {
classA objectA = new classA();
//more code
}
public void methodA() {
//even more code
}
}
public class classB {
public void someListener() {
//code needed to call methodA of the object objectA
}
}
The question is: what would the code be, where there is now just the comment //code needed to call methodA of the object objectA?
The reason I'm in this situation, is that in the code that I'm going to use it for, there are various methods running in objectB controlled by loops, but once a certain thing happens a method in what is shown here as objectA has to be called. How do I do this?