Employee.java
package com.togeek;
import java.util.Date;
public class Employee {
public Employee() {
// TODO Auto-generated constructor stub
}
public static void main(String[] arg) throws InterruptedException{
System.out.println("现在时间"+new Date().toLocaleString());
Thread.sleep(1000);
Boss.getBoss().say();
Thread.sleep(3000);
Boss.getBoss().say();
}
}
Boss.java
package com.togeek;
import java.util.Date;
/**
*这是一个大BOSS应该就有一个
*/
public class Boss {
private static final Boss boss=new Boss();//这boss进来就有了
private Boss() {}//私有的不能new
private Date sayTime=null;
public static Boss getBoss(){
return boss;
}
public void say(){
if(null==sayTime)sayTime=new Date();
System.out.println("boss说"+sayTime.toLocaleString()+"放假");
}
}
网友评论