package com.haha.单例;
package com.haha.单例;
//懒汉
public class Dog {
private static Dog dog=new Dog();
public static Dog NEW(){
return dog;
}
public static Dog sound(){
System.out.println("汪汪....");
return dog;
}
public static Dog eat(){
System.out.println("正在找骨头吃");
return dog;
}
private Dog(){}
}
package com.haha.单例;
public class Test2 {
/**
* @param args
*/
public static void main(String[] args) {
Dog dog=Dog.NEW();
dog.sound().eat().sound().eat();
Cat cat=Cat.NEW();
cat.sound();
cat.eat();
cat.sound();
cat.eat();
}
}
posted on 2015-11-06 19:57 kebizhanmushi 阅读(104) 评论(0) 编辑 收藏 举报