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).

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Продовжуйте вивчати
тести з Java
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести