I have class C1 and class C2.
C1 has a public boolean variable b1.
The value of b1 is set in C1 and then I create a object of Class C2 in C1.
ie in C1 I have :
b1 = true;
C2 c2 = new C2();
Now in constructor of C2 , I want to make a decision based on the value of b1.
How can I access the value of b1 (which is a variable of Class C1) in the constructor of C2 ?
The constructor of C2 cannot have any arguements.
If b1 is not declared static, and C1 is not a singleton, and you can't pass the instance of C1 as an argument to the constructor of C2, you're out of luck.
Unless you make C2 an inner class of C1, of course.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.