2020526-接口的练习

 1 //定义人的抽象类
 2 abstract class Human{
 3     //吃饭
 4     abstract void eat();
 5 }
 6 
 7 //中国人
 8 
 9 class Chinese extends Human{
10 
11     @Override
12     void eat() {
13         // TODO Auto-generated method stub
14         
15     }
16     
17 }
18 
19 //学生类继承中国人
20 class Student extends Chinese{
21     //学生具有学习行为
22     public void study() {
23         System.out.println("i am studing...");
24     }
25 }
26 
27 //老师类继承中国人,继承抽烟和游泳接口
28 class Teacher extends Chinese implements Smoke,Swim{
29     //老师具有吃饭、抽烟、教书、游泳行为
30     
31     public void teach() {
32         System.out.println("教书");
33     }
34 
35     @Override
36     public void swim() {
37         // TODO Auto-generated method stub
38         System.out.println("游泳");
39     }
40 
41     @Override
42     public void smoke() {
43         // TODO Auto-generated method stub
44         System.out.println("抽烟");
45     }
46     
47 }
48 
49 //定义抽烟和游泳的接口
50 
51 interface Smoke{
52     void smoke();
53 }
54 interface Swim{
55     void swim();
56 }
57 
58 
59 //美国人
60 
61 class Amerivcan extends Human{
62 
63     @Override
64     void eat() {
65         // TODO Auto-generated method stub
66         
67     }
68     
69 }
70 
71 //印度人
72 class Indian extends Human implements BaiS{
73 
74     @Override
75     void eat() {
76         // TODO Auto-generated method stub
77         
78     }
79 
80     @Override
81     public void bais() {
82         // TODO Auto-generated method stub
83         
84     }
85     
86 }
87 
88 //拜神接口
89 interface BaiS{
90     void bais();
91 }

 

posted @ 2021-05-27 18:52  yekaiIT  阅读(50)  评论(0编辑  收藏  举报