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
Зарегистрируйся сейчас
или Подпишись на будущие тесты