Which of the following statements are true?
a. A constructor can invoke another constructor of the same class using the constructor invocation statement "this".
b. A constructor can invoke itself using the constructor invocation statement "this".
c. The constructor invocation statement, "this", can legally appear anywhere in the constructor body.
d. A constructor can invoke the constructor of the direct superclass using the superclass constructor invocation statement "super".
e. The number of constructor invocation statements that may appear in any constructor body can equal but not exceed the number of alternate constructors declared in the same class.
f. A constructor is not permitted to throw an exception.
g. None of the above.
The correct answers are A and D
But my doubt is related to option B that is given. The answer given to justify B is :
"A compile-time error is generated if a constructor attempts to invoke itself either directly or indirectly"
I had also marked it true, but later found out that the compiler cries out foul if I have code like this.
But if I comment this() statement at line marked 1, and uncoment the next line, i.e new A(), the thing does not create a compiler error, though and infinite loop is create and the system soon runs out of stack.
Can anybody please provide a justification for this behaviour. Why is new A() allowed and not this() ??
Rgds,
Anupreet