package jave;
/*接口*/
/*接口可以多重实现
* 接口中声明的属性的默认值为public static final的;也只能是public static final的
* 接口中的只能定义抽象方法,而这些方法默认值为public,也只能是public的
* 接口可以继承其他的接口,并添加新的属性和抽象方法
* 可以利用接口实现多继承和多态
*/
interface Valuable { //定义接口
public double getMoney();//定义抽象方法
}
interface Protectable {
public void beProtected();
}
interface A extends Protectable {//接口可以继承其他的接口
void m();
}
abstract class Anima {
private String name;
abstract void enjoy();
}
//实现多继承
public class GoldenMokey extends Anima implements Valuable, Protectable {
public double getMoney() {
return 1000;
}
public void beProtected() {
System.out.println("live in room");
}
public void enjoy() {
System.out.println("I'm enjoying !");
}
public static void main(String[] args) {
Valuable v = new GoldenMokey();
System.out.println("价值: " + v.getMoney() );
GoldenMokey g = new GoldenMokey();
g.enjoy();
Protectable p = (Protectable)v;
p.beProtected();
}
}