A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 张凡 中级黑马   /  2013-9-8 17:02  /  727 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

以下代码说明延迟加载了吗?如何体现的?
public class Test{       
        static class People{
                private String name;
                private String sex;
                private int age;
                private People(String name,String sex,int age){
                        super();
                        this.name=name;
                        this.sex=sex;
                        this.age=age;
                }
                public static People p=null;
                public static People getPeople(){
                        synchronized (People.class){
                                if(p==null){
                                        p=new People("zhangfan","女",22);
                                }
                        }
                        return p;
                }
                 public String toString() {  
                      return "姓名:"+name+"      年龄: "+age;  
              }
        }
        public static void main(String[] args) {  
                People p1=People.getPeople();
                People p2=People.getPeople();  
                People p3=People.getPeople();  
        System.out.println(p1);  
        System.out.println(p2);  
        System.out.println(p3);  
        
    }  
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马