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

原文地址:https://www.cnblogs.com/wjchang/p/3671640.html