JAVA课程6 用接口编写动物模拟器

interface Animal
{
	abstract void Cry();
	abstract void GetAnimalName();
}

class Simulator
{
	void playSound(Animal animal)  
     {  
     animal.GetAnimalName();  
     animal.Cry();  
     }  
	
	
}
public	 class D_c implements Animal //接口
{
public void Cry()
{
System.out.println("say:emmmmmiao???");
}
public void GetAnimalName()
{
System.out.println("Cat");
}
}

public	 class D_c1 implements Animal
{
public void Cry()
{
System.out.println("say:wuwuwuwuwuwang???");
}
public void GetAnimalName()
{
System.out.println("Dog");
}
}
    public class APPlication   
    {  
       public static void main(String args[])  
          {  
      Simulator simulator=new Simulator();  
        simulator.playSound(new D_c());  
          simulator.playSound(new D_c1());  
          }  
     }  


JAVA课程6 用接口编写动物模拟器_第1张图片

你可能感兴趣的:(JAVA课程6 用接口编写动物模拟器)