[Java] 接口-02
来源:互联网 发布:阿里云lamp一键安装包 编辑:程序博客网 时间:2024/05/17 06:36
package com.bjsxt.chap03;public interface Valuable { public double getMoney();}interface Protectable { public void beProtected();}interface A extends Protectable { void m(); // void getMoney();}abstract class Animals { private String name; abstract void enjoy();}class GoldenMonkey extends Animals 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 GoldenMonkey(); v.getMoney(); Protectable p = (Protectable)v; p.beProtected(); }}class Hen implements A { public void m() {} public void beProtected() {} public double getMoney() { return 1.0; } // public void getMoney() {} // 不常见,怪异的问题}