[size=1em]1 [size=1em]2 [size=1em]3 [size=1em]4 [size=1em]5 [size=1em]6 [size=1em]7 [size=1em]8 [size=1em]9 [size=1em]10 [size=1em]11 [size=1em]12 [size=1em]13 [size=1em]14 [size=1em]15 [size=1em]16 [size=1em]17 [size=1em]18 | [size=1em][size=1em]class Single{ [size=1em] //一加载类,对象就已经存在了 [size=1em] private static Single s = new Single(); [size=1em] private Single(){} [size=1em] public static Single getInstance(){ [size=1em] return s ; [size=1em] } [size=1em]} [size=1em]class SingleDemo{ [size=1em] public static void main(String[] args){ [size=1em] Single s1 = Single.getInstance(); [size=1em] Single s2 = Single. getInstance(); [size=1em] System.out.println(s1 == s2); [size=1em] } [size=1em]} |
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |