Kann mir jemand erklären wie ich das Feld instance initialisiere und wo?
package de.codegym.task.task15.task1522;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
/*
Singleton-Muster festigen
*/
public class Solution {
public static void main(String[] args) {
}
public static Planet thePlanet;
// Hier statischen Block einfügen
static {
readKeyFromConsoleAndInitPlanet();
}
public static void readKeyFromConsoleAndInitPlanet() {
// Hier Schritt #5 implementieren
while(true) {
Scanner sc =new Scanner(System.in);
String s = sc.next();
if (s.equals("Sonne")) {
Sun SUN = new Sun();
thePlanet=SUN;
}
else if (s.equals("Mond")){
Moon MOON = new Moon();
thePlanet=MOON;
}
else if (s.equals("Erde")) {
Earth EARTH = new Earth();
thePlanet=EARTH;
}
else
thePlanet=null;
break;
}
}
}
class Sun implements Planet {
private static Sun instance;
public static Sun getInstance() {
Sun instance = null;
return instance;
}
}
class Moon implements Planet {
private static Moon instance;
public static Moon getInstance() {
return instance;
}
}
class Earth implements Planet {
private static Earth instance;
public static Earth getInstance() {
return instance;
}
}