单例模式

package Demo;

public class Demo1 {
    
    public static void main(String[] args) {
        Single s=Single.getInstanceof();
        Single s1=Single.getInstanceof();
        s.setName("liliang");
        String d=s1.getName();
        System.out.print(d);
    }
}
class Single
{
    private String name;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public static Single getS() {
        return s;
    }
    public static void setS(Single s) {
        Single.s = s;
    }
    private static Single s=new Single();
    private Single(){}
    public static Single getInstanceof()
    {
        return s;
    }
}

posted on 2012-10-19 17:15  蝌蚪的精神  阅读(129)  评论(0编辑  收藏  举报

导航