package com.hr.单例模式;
/**
* @ClassName Student
* @Description: TODO
* @Author 汤永红
* @Date 2020/8/7 0007-11:05
* @Version V1.0
**/
public class Student {
//静态属性
static Student student;
//构造方法私有
private Student() {
}
//提供一个公共的方法供外界调用,以获得实例
public static Student getStudentInstance() {
if (student == null) {
student = new Student();
}
return student;
}
public static void main(String[] args) {
Student s1 = Student.getStudentInstance();
Student s2 = Student.getStudentInstance();
System.out.println(s1 == s2);
}
}