Hi Luanrkiran kumar.
Luanrkiran kumar wrote:
I just want to know how the above code works..and what to do to get rid of stack overflow error.
-
a is an isntance of Bird, which is instantiated at construction of Bird object
- When you construct a Bird object
a is instantiated calling the Bird constructor another time.
- So every time you call new Bird(),
a is created calling new Bird() again.
- So for
Bird bird = new Bird(), This code cicles endlessly creating an abject like bird.a.a.a.a.a.a.a.a ....
To escape this code you can change the code in various way.
One option I suggest is to set the variable
a static