package com_cc.Private;
/**
* @author CC
* @version 1.0
* 单例模式饿汉式
*/
public class Single01 {
public static void main(String[] args){
Girl gf = Girl.getGf();
System.out.println(gf);//Girl{name='小红'}
}
}
class Girl{
String name;
private static Girl gf = new Girl("小红");
private Girl(String name){
this.name = name;
}
public static Girl getGf() {
return gf;
}
@Override
public String toString() {
return "Girl{" +
"name='" + name + '\'' +
'}';
}
}