本帖最后由 郭晓晨 于 2013-12-19 12:46 编辑
- class Single
- {
- private static Single s = new Single();
- private Single(){}
- public static Single getInstance()
- {
- return s;
- }
- }
- class SingleInstanceDemo
- {
- public static void main(String[] args)
- {
- Single s1 = Single.getInstance();
- Single s2 = Single.getInstance();
- }
- }
复制代码
关于单例设计模式这一段代码有个问题想请教大家
执行主函数Single s2 = Single.getInstance();这一句的时候Single还会被加载一次吗?private static Single s = new Single(); 这句还会再执行一次吗? |