java例程练习(接口interface)

interface Valuable {
	public double getMoney();
}

interface Protectable {
	public void beProtected();
}

interface A extends Protectable {
	void m();
}


abstract class Animal {
	private String name;
	
	abstract void enjoy();

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}
}

class GoldMonkey extends Animal implements Valuable, Protectable {
	public double getMoney() {
		return 10000;
	}
	
	public void beProtected() {
		System.out.println("Live in the room");
	}
	
	public void enjoy() {
		
	}
	
	public void test () {
		Valuable v = new GoldMonkey();
		v.getMoney();
		Protectable p = (Protectable) v;
		p.beProtected();
	}
}

class Hen implements A {
	public void m(){}
	public void beProtected(){}
}

posted on 2012-04-22 18:21  Yours风之恋  阅读(175)  评论(0编辑  收藏  举报