//接口:抽象方法和常量值的集合。而且都是public类型,不写,默认也是public,而常量经常写成:public static final int id=1;
//不管是抽象类还是接口,他们都不能被实例化,只能被子类继承,而且他们的方法必需都得重写。
package com.ch3.test;
interface Valuable1 {
public double getMoney();
}
interface Protectable {
public void beProtected();
}
abstract class Animal1 {
private String name;
abstract void enjoy();
}
class GoldenMonkey extends Animal1 implements Valuable1, Protectable {
public double getMoney() {
return 10000;
}
public void beProtected() {
System.out.println("live in the room");
}
public void enjoy() {
}
}
public class TestInterface {
/**
* @param args
*/
public static void main(String[] args) {
Valuable1 v = new GoldenMonkey();
System.out.println(v.getMoney());
Protectable p = (Protectable)v;
p.beProtected();
}
}