2019.2.18接口

Posted zhangchuanfeng1

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2019.2.18接口相关的知识,希望对你有一定的参考价值。

技术图片

父类手机类:

 1 package com.phone;
 2 
 3 public abstract class Phone {
 4     public String brand;
 5     public String type;
 6     
 7     public Phone(String brand, String type) {
 8         super();
 9         this.brand = brand;
10         this.type = type;
11     }
12     
13     public abstract void send();
14     public abstract void call();
15     
16 }

拍照接口:

1 package com.phone;
2 
3 public interface Photo {
4     public void photo();
5 }

音频接口:

1 package com.phone;
2 
3 public interface Music {
4     public void music();
5 }

播放接口:

1 package com.phone;
2 
3 public interface Play {
4     public void play();
5 }

上网接口:

1 package com.phone;
2 
3 public interface Inter {
4     public void inter();
5     
6 }

普通手机:

 1 package com.phone;
 2 
 3 public class CommonPhone extends Phone implements Music{
 4 
 5 
 6     public CommonPhone(String brand, String type) {
 7         super(brand, type);
 8         // TODO Auto-generated constructor stub
 9     }
10 
11     public void send() {
12         System.out.println("发短信");
13         
14     }
15 
16     public void call() {
17         System.out.println("打电话");
18     }
19 
20     @Override
21     public void music() {
22         // TODO Auto-generated method stub
23         System.out.println("播放音频");
24         
25     }
26 
27 }

 

智能手机:

 1 package com.phone;
 2 
 3 public class ZhiNengPhone extends Phone implements Music,Photo,Play,Inter{
 4 
 5     public ZhiNengPhone(String brand, String type) {
 6         super(brand, type);
 7         // TODO Auto-generated constructor stub
 8     }
 9 
10     @Override
11     public void send() {
12         // TODO Auto-generated method stub
13         System.out.println("发短信");
14     }
15 
16     @Override
17     public void call() {
18         // TODO Auto-generated method stub
19         System.out.println("打电话");
20     }
21 
22     @Override
23     public void inter() {
24         // TODO Auto-generated method stub
25         System.out.println("上网");
26     }
27 
28     @Override
29     public void play() {
30         // TODO Auto-generated method stub
31         System.out.println("播放");
32     }
33 
34     @Override
35     public void photo() {
36         // TODO Auto-generated method stub
37         System.out.println("拍照");
38     }
39 
40     @Override
41     public void music() {
42         // TODO Auto-generated method stub
43         System.out.println("播放音频");
44     }
45 
46 }

测试类:

 1 package com.phone;
 2 
 3 public class Test {
 4     public static void main(String[] args) {
 5         CommonPhone phone = new CommonPhone("诺基亚", "A3");
 6         System.out.println("这是一部"+phone.brand+",型号为"+phone.type);
 7         phone.send();
 8         phone.call();
 9         phone.music();
10         System.out.println("****************");
11         ZhiNengPhone zn = new ZhiNengPhone("苹果", "6s");
12         System.out.println("这是一部"+zn.brand+",型号为"+zn.type);
13         zn.call();
14         zn.send();
15         zn.inter();
16         zn.music();
17         zn.photo();
18         zn.play();
19     }
20 }

输出:

技术图片

 

以上是关于2019.2.18接口的主要内容,如果未能解决你的问题,请参考以下文章

从父片段到选项卡片段的接口侦听器不起作用

与另一个片段通信的片段接口

java 代码片段

无法通过接口获取与片段通信的活动

将接口从片段传递到kotlin中的活动

是否可以动态编译和执行 C# 代码片段?