Your class does not have an instance of the other class to operate on- you will have to pass it one.
ClassA myClassA;ClassB myClassB;myClassA = new ClassA(myClassB);myClassB = new ClassB(myClassA);myClassA.query();myClassB.query();myClassB.queryClassA();myClassA.queryClassB();
Then
class ClassA {//attributes and methods in hereClassB classBInstance;private int noOfQueries=0;private String name="A";public void query(){System.out.println("\nQuery result: My name is '"+name+"' Previous queries = "+noOfQueries);noOfQueries++;}public void queryClassB(){// you can query your instance of class B here}// constructorpublic ClassA(ClassB classBInstance){this.classBInstance = classBInstance;System.out.println("\nA new object has been instantiated from ClassA");}}
Class A now has an instance of class B to query.
That should work, but I don't have my compiler installed and my Java is a little rusty :/
Depending on what information you want from the other class, you could consider using
static members.
You could also pass an instance of the class you wish the query into the function queryClassB, ie. myClassA.queryClassB(myClassB); and operate on that.