+ 1
why there is an error
class A{ int b = 6; int c = 7; A f = new A();// generate a error } why?
5 Answers
+ 2
David Yan You got StackOverflowError. Your A class has an instance of itself. When you create A class in your first example, another instance of A is created (A f = new A). This new instance f needs another instance of A, then another and so on, until you are out of memory.
This error does not occur in the second example, because you do not initialize the inner object of A f. When you are creating instance of A in your main method, no other instances of A are created.
+ 4
its showing error defination of A is not complete
may be đYou creating object of class A inside of body . Why u need to create First read about class and object why we need of object .
+ 3
Because A is not defined
+ 3
David Yan What error is thrown?
Your code compiles.
It is allowed to initialize objects inside body.
https://code.sololearn.com/cmJi6i6y43TY/?ref=app