描述Single对象:
package android.java.oop14; public class Single { // 默认构造方法 私有化 不让外界调用
private Single() {} private static final Single SINGLE = new Single(); public static Single getSingle() {
return SINGLE;
} public void printlnData() {
System.out.println("---> 显示数据...");
}
}
main测试方法:
package android.java.oop14; public class SingleDemo { public static void main(String[] args) { Single single = Single.getSingle(); single.printlnData(); } }