单例类是只能用于创建一个实例的类。
class SingletonClass { private static SingletonClass instance;/* 来自 时 代 J a v a - N o w J a v a . c o m*/ private SingletonClass() { } public static SingletonClass getInstance() { if (instance == null) instance = new SingletonClass(); return instance; } } public class Main { public static void main(String[] args) { /** 来 自 n o w j a v a . c o m **/ SingletonClass s1 = SingletonClass.getInstance(); SingletonClass s2 = SingletonClass.getInstance(); if (s1 == s2) System.out.println(