Jack Dowson said:
Lasse Reichstein Nielsen ??:
If there are class A in which main method exists and class B,they are in
the same folder(module).In the defination of class A there is a sentence
"B b = new B();" while in the defination of class B there is "A a = new
A();".
This is a little different from what you told us first. The first time around
you said each class employed the other, which I would assume means each class
uses the other. Not an issue.
But, if you are creating (as in, to instantiate) class A, which creates
class B, which creates class A - you run into a loop that won't end.
You can compile the folowing two classes just by typing "javac A.java",
but be ready to hit ^C after you type in "java A":
public class A {
public static void main(String[] args) {
A a = new A();
}
public A()
{
System.out.println("Making A");
B b = new B();
System.out.println("Done with A");
}
}
public class B {
public B() {
System.out.println("Making B");
A a = new A();
System.out.println("Done with B");
}
}
When you run it, notice that you will never get "Done with [AB]".
- Kurt