package com.yunchao.test;
/**
* 單例設計模式
* 1.將構造函數私有化,這樣其他的類就不能new出來這個類的對象
* 2.自己在類裏面new出來一個對象
* 3.把new出來的對象提供出去,應爲其他對象不能夠通過對象來調用暴露的方法,所以方法應該
* 設計成static的,通過類名來調用,然後就是static方法裏的變量也要是static的
* @author yunchao
*
*/
public class Singleton {
public static void main(String[] args) {
single s1=single.getsingle();
}
}
class single{
private single(){}
private static single s=new single();
public static single getsingle(){
return s;
}
}