class Singleton{ private static Singleton instance = new Singleton(); private Singleton(){ } public static Singleton getInstance(){ return instance; } public void print(){ System.out.println("Hello Word"); } } public class singleton { public static void main(String[] args) { // TODO 自动生成的方法存根 Singleton s1 = Singleton.getInstance(); Singleton s2 = Singleton.getInstance(); Singleton s3 = Singleton.getInstance(); s1.print(); s2.print(); s3.print(); } }
时间: 2024-11-04 19:08:27