/**
* 单例模式
*
* @author young
*
*/
public
class
Singleton {
private
static
Singleton instance;
private
Singleton() {
}
public
static
Singleton getInstance() {
if
(instance ==
null
) {
instance =
new
Singleton();
}
return
instance;
}
public
static
void
main(String[] args) {
Singleton s1 = getInstance();
Singleton s2 = getInstance();
if
(s1.equals(s2)){
System.out.println(
"单例模式只有一个实例."
);
}
else
{
System.out.println(
"单例模式例子失败."
);
}
}
}