I have the following classes.
public class B { public A a; public B() { a= new A(); System.out.println(\"Creating B\"); }
It isn't necessarily as easy as in your example. I believe solving this problem would be equal to solving the halting problem which -- as we all know -- is impossible.