Which statements about the following code are correct ? (in some application):

public class Singleton {
     private static Singleton singleton;
     public static Singleton getInstance() {
          if (singleton == null) {
              singleton = new Singleton();
          }
          return singleton;
     }
}
Explanation
Many instances of class Singleton can be created - constructor is not private.
Several threads can simultaneously enter the if statement and create several different objects (because synchronization is not used).

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes