抽象类的定义与使用

 1 abstract class Action {
 2  public static final int ECT=1;
 3  public static final int WROLD=2;
 4  public static final int Sleep=7;
 5  public void cmmand(int fag){
 6     switch (fag)
 7     {
 8     case ECT:{
 9      this.ect();
10     break;}
11     case WROLD:{
12       this.wrold();
13       break;
14               }
15     case Sleep:{
16       this.sleep();
17       break;
18       }
19     }
20     }
21  public abstract void ect();
22  public abstract void wrold();
23  public abstract void sleep();
24 }
25 class roblt extends Action{
26     public void ect(){
27     System.out.println("正在吃饭中");
28     }
29     public void wrold(){
30     System.out.println("正在工作中");
31     }
32     public void sleep(){}
33 }
34 class human extends Action{
35     public void ect(){
36     System.out.println("正在吃饭中");
37     }
38     public void wrold(){
39     System.out.println("正在工作中");
40     }
41     public void sleep(){
42     System.out.println("正在睡觉中");
43     }
44 }
45 class pig extends Action{
46     public void ect(){
47     System.out.println("正在吃饭中");
48     }
49     public void wrold(){}
50     public void sleep(){
51     System.out.println("正在睡觉中");
52     }
53 }
54 public class Noname1
55 {public static void main(String args[]){
56    System.out.println("**********猪*********");
57    fun(new pig());
58     System.out.println("********人**********");
59     fun(new human());
60     System.out.println("********机器人*****");
61     fun(new roblt());
62    }
63 public static void fun(Action act){
64    act.ect();
65    act.wrold();
66    act.sleep();
67    }
68 }

 

posted @ 2016-09-24 15:42  as145  阅读(326)  评论(0编辑  收藏  举报