第03章 面向对象 44 interface2

来源:互联网 发布:sql分组查询所有数据 编辑:程序博客网 时间:2024/05/01 10:03
//Valuable.javapublic interface Valuable {public double getMoney();}interface Protected {public void beProtected();}interface A extends Protected {public void m();}abstract class Animal {private String name; abstract void enjoy();}class GoldenMonkey extends Animal implements Valuable, Protected {public double getMoney() {return 100000;}public void beProtected() {System.out.println("live in the room");}void enjoy() {}public void test() {Valuable v = new GoldenMonkey();v.getMoney();Protected p = (Protected)v;p.beProtected();}}class Hen implements A {public void m() {}public void beProtected() {}}/*public class TestValuable {}*/


注意点:public interface和public class 的效果是相同的!也就是程序只能有一个public类或interface接口!自己的见解

 

鱼欲遇雨:每日都学习一点,持之以恒,天道酬勤!不能用电脑时,提前补上!(2012.9.6)

 

原创粉丝点击