I am recently asked about java related question in an interview with following code, since I am very new to java and barely code in Java so I really have no idea what the following code does.
The question was Select the option that describes the worst thing with the following code:
public class Bolton {
private static Bolton INST = null;
public static Bolton getInstance()
{
if ( INST == null )
{
INST = new Bolton();
}
return INST;
}
private Bolton() {
}
}
Here are the options for this question
- More than one instance of Bolton can be created
- A Bolton will never be created
- The constructor is private and can't be called
- Value can be garbage collected, and the call to getInstance may return garbage data
Which of the above options is correct? And Why?