Your code where you are assigning memory to a variable at the class level will give stack overflow error.
It is because when you assign memory to an object, it allocates memory space to all the instance variables and the functions.
In you case you are creating an object "a" of class X. When you do this, the JVM will start allocating memory to the instance variables.
In your case, "b" is an instance variable to which you are assigning memory at the class level. Since "b" is also an object, the JVM will
again go to assign memory space to the instance variables of class X (which is b in our case). Hence this process will keep on going
till you run out of memory.
So in order to avoid this problem, if you are creating an object of a class as its instance member, avoid assigning memory to it at the class level
or in the constructor.