标签:方法 oid public abstract ext new div return mon
1. 接口与接口之间可以相互继承;
2. 类与类之间可以相互继承;
3. 类与接口之间,只能是类来实现接口;
4. 继承已经具有父类的方法,子类可以不重写父类方法;类在实现接口的时候,必须重写接口所有的方法.
5. Demo
interface Valuable {
public double getMoney();
}
interface Protectable {
public void beProtectable();
}
interface A extends Protectable {
public void m();
}
abstract class Animal {
private String name;
public abstract void enjoy();
}
class GolddenMonkey extends Animal implements Valuable, Protectable {
public void beProtectable() { //@Override
System.out.println("live in the room");
}
public double getMoney() { //@Override
return 10000;
}
public void enjoy() { //@Override
}
public void test(){
Valuable v = new GolddenMonkey();
v.getMoney();
Protectable p = (Protectable) v;
p.beProtectable();
}
}
class Hen implements A {
public void beProtectable() { //@Override
System.out.println("live in the garden");
}
public void m() { //@Override
System.out.println("Hen eat rice");
}
}
// 正确
标签:方法 oid public abstract ext new div return mon
原文地址:http://www.cnblogs.com/bosongokay/p/6746284.html