class A
{
B obj;
// Parameterized constructor with object of B as a parameter
A(B obj) // 4
{
this.obj = obj; // 5
// calling display method of class B
obj.display(); // 6
}
}
class B
{
int x = 5;
// Default Contructor that create a object of A with passing this as an argument in the constructor
B() // 2
{
A obj = new A(this); // 3
}
// method to show value of x
void display() // 7
{
System.out.println("Value of x in Class B is " + x); // 8
}
public static void main(String[] args) {
B obj = new B();
}
}
public class Main
{
public static void main(String[] args)
{
B obj = new B(); // 1
}
}