在 JDK1.8,允许我们给接口添加两种非抽象的方法实现:

1、默认方法,添加 default 修饰即可;

2、静态方法,使用 static 修饰;示例如下:

这样可以实现接口的增强,那我们在类实现接口的时候如何用呢,我们举例来说明:

首先,我有一个Inteface的接口,如下:Inteface.java:

package Inteface;

public interface Inteface {
default String get(String aa){
System.out.print(aa);
return "";
}
static void state(){
System.out.print("state");
};
}

  这里面我写了一个默认方法和静态方法,以实现接口的加强,那么,看一下我们的来实现接口是怎么写的吧:

IntefaceS.java:

package Inteface;

public class IntefaceS implements Inteface {
public static void move() {
System.out.print("hahah");
} public static void main(String args[]) {
IntefaceS inte = new IntefaceS();
inte.get("123");
Inteface.state();
}
}

 由于在接口中使用了static关键字,所以这里再勒种使用的时候需要使用接口去掉方法,这里和类的继承非常相似了;

好吧,看结果 

最新文章

  1. 实现如下类之间的继承关系,并编写Music类来测试这些类。
  2. linux tricks 之VA系列函数.
  3. ByteBuffer
  4. java内部类的继承
  5. Unity3D的LightProbe动态光探头用法介绍
  6. vm内核参数优化设置
  7. IOS,发短信,发邮件,打电话
  8. [翻译]ASP.NET Web API的路由
  9. HttpClient 发送图片
  10. css实现两端对齐的3种方法
  11. javascript 简易文本编辑器
  12. 高性能平滑动画_requestAnimationFrame
  13. linux和shell的学习记录
  14. Mysql出现(10061)错误提示的暴力解决办法
  15. 指导手册05:MapReduce编程入门
  16. Python scrapy - Login Authenication Issue
  17. BIOS 搭配 MBR/GPT 的开机流程
  18. transform.forward和vector3.forward
  19. uc浏览器app点评
  20. c递归程序

热门文章

  1. python 调用pymysql模块遇到\转义问题解决办法
  2. python新模块:secrets模块(为账户密码)
  3. mysql 查看某个库下面某个表的所有列字段, columnName
  4. 【转】【MySQL】Mysql模糊查询like提速优化
  5. SpringBoot系列九:SpringBoot服务整合(整合邮件服务、定时调度、Actuator监控)
  6. Spring系列(四):Spring AOP详解和实现方式(xml配置和注解配置)
  7. e612. Moving the Focus to the Next or Previous Focusable Component
  8. 升级win10,提示(RAM)内存不足2G的解决的方法,亲測可行
  9. mothur trim.seqs 去除PCR引物
  10. List&Map&Set的操作和遍历