Back to slide -- Keyboard shortcut: 'u'        next  SingletonDemo.java - Skabelonen for en Singleton klasse i Java.Lecture 15 - slide 15 : 31
Program 1

class Singleton {

  protected int singletonData;
  private static Singleton uniqueInstance = null;
  
  private Singleton(){
    // initialisering af data:
    singletonData = 5;
  }

  public static Singleton instance() {
    if (uniqueInstance == null)
       uniqueInstance = new Singleton();
    return(uniqueInstance);
  }

  // Singleton instansmetoder:
  // ...

} // end Singleton