public class Singleton {
private static Singleton instance = new Singleton();
private Singleton(){};
public static Singleton getInstance(){
return instance;
}
public static void main(String[] args){
Wife w1 = new Wife();
Singleton s1 = w1.husband();
Wife w2 = new Wife();
Singleton s2 = w2.husband();
System.out.println(s1 == s2);
}
}
public class Wife {
public Singleton husband(){
return Singleton.getInstance();
}
}