public class Employee {
Employee e = null;
Employee(){
if(e == null)
e = new Employee();
return e;
}
}
- We know constructor don't have any return type but it can still return object of the class itself. Interesting may be there is Abstract Constructor Pattern and this is the basis. Some one will discover soon.
- Interviewee confirmed thrice with confidence that this code not only compiles but at run time it doesn't end up in recursion calling constructor of class again from constructor again with a condition that is not on static variable.