자바 동물 소리 "시 뮬 레이 터"

1127 단어
package mypackage;

public abstract class Animal {
	public abstract void cry();
	public abstract String getAnimalName();
}
package mypackage;

public class Simulator {
	public void playSound(Animal animal){
		System.out.println("  "+animal.getAnimalName());
		System.out.println("     :");
		animal.cry();
	}
}
package mypackage;

public class Dog extends Animal{
	public void cry(){
		System.out.println(" 、 、 ");
	}
	public String getAnimalName(){
		return "  ";
	}
}
package mypackage;

public class Cat extends Animal{
	public void cry(){
		System.out.println(" 、 、 ");
	}
	public String getAnimalName(){
		return "  ";
	}
}
package mypackage;

public class Test {
	public static void main(String[] args) {
		Simulator simulator=new Simulator();
		simulator.playSound(new Dog());
		simulator.playSound(new Cat());
	}

}

좋은 웹페이지 즐겨찾기