Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1427987
  • 博文数量: 842
  • 博客积分: 12411
  • 博客等级: 上将
  • 技术积分: 5772
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-14 14:43
文章分类

全部博文(842)

文章存档

2013年(157)

2012年(685)

分类:

2012-05-07 22:32:36

原文地址:Java 接口 作者:luozhiyong131


点击(此处)折叠或打开

  1. public interface Valuable {
  2.     public double getMoney();
  3. }

  4. interface Protectable {
  5.     public void beProtected();
  6. }

  7. interface A extends Protectable {
  8.     void m();
  9.     void getMoney();
  10. }

  11. abstract class Animal {
  12.     private String name;
  13.     
  14.     abstract void enjoy();
  15. }

  16. class GoldenMonkey extends Animal implements Valuable, Protectable {
  17.     public double getMoney() {
  18.         return 10000;
  19.     }
  20.     
  21.     public void beProtected() {
  22.         System.out.println("live in the room");
  23.     }
  24.     
  25.     public void enjoy() {
  26.         
  27.     }
  28.     
  29.     public void test() {
  30.         Valuable v = new GoldenMonkey();
  31.         v.getMoney();
  32.         Protectable p = (Protectable)v;
  33.         p.beProtected();
  34.     }
  35. }

  36. class Hen implements A {
  37.     public void m() {}
  38.     public void beProtected() {}
  39.     public double getMoney() {
  40.         return 1.0;
  41.     }
  42.     
  43.     public void getMoney() {}

  44. }

阅读(313) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~