Bootstrap

JAVA面向接口编程课堂练习(马戏团)

在这里插入图片描述

package com;

public interface IAction {
    public void show();
    public void lan(); 
}


package com;

public interface IAnimal  extends IAction{
	   

}

package com;

public abstract class Actor implements IAnimal{
    public String name;
	@Override
	public abstract void show() ;

	@Override
	public abstract void lan() ;

}

package com;

public class Dog extends Actor{
 
	public Dog() {
		this.name="狗";
	}
	
	@Override
	public void show() {
		// TODO Auto-generated method stub
		System.out.println("狗狗开始表演,背上小背篓,站立行走");
	}

	@Override
	public void lan() {
		// TODO Auto-generated method stub
		System.out.println("看图识数,汪汪汪");
	}

}

package com;

public class Monkey extends Actor {

	public Monkey() {
		this.name="猴子";
	}
	
	
	@Override
	public void show() {
		// TODO Auto-generated method stub
		System.out.println("猴子开始表演,跳钢圈,走钢丝");
	}

	@Override
	public void lan() {
		// TODO Auto-generated method stub
		System.out.println("拉着你的手,亲爱的你别走!");
	}

}

package com;

public class Circus {
   //定义马戏团
   private Actor act;
   
   public void enter(Actor act) {
	   this.act=act;
	   System.out.println(this.act.name+"进场啦");
   }
	
   public void show() {	   
	   this.act.show();	   
   }
   
   public void lan() {
	   this.act.lan();	   
   }
   
	
	
}

package com;

public class TestPlay {

	public static void main(String[] args) {
		Circus c=new Circus();   //马戏团创建		
		Monkey mon=new Monkey();
		Dog dog=new Dog();		
		//		c.enter(mon);   //猴子进场		
				c.show();
		//		c.lan();			
		c.enter(dog);   //狗进场
		c.show();
		c.lan();
	}

}

狗进场啦
狗狗开始表演,背上小背篓,站立行走
看图识数,汪汪汪
;