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();
}
}