java 28

JDK8的新特性: http://bbs.itcast.cn/thread-24398-1-1.html

其中之一:接口可以使用方法

  

 1 interface Inter
 2 {
 3         //抽象方法
 4         public abstract void show();
 5         
 6         //default方法
 7         public default void defaultPrint() 
 8         {
 9                 System.out.println("defaultPrint JDK8接口可以使用方法了");
10         }
11 
12         //static方法
13         public static void staticPrint()
14         {
15                 System.out.println("staticPrint JDK8接口可以使用方法了");
16         }
17 }
18 
19 //实现类
20 class InterImpl implements Inter
21 {
22         public void show()
23         {
24                 System.out.println("重写接口中的方法");
25         }
26 }
27 
28 //测试类
29 public class Demo01 
30 {
31         public static void main(String[] args) 
32         {
33             //Inter.defaultPrint();     //非静态方法不能直接使用 
34             Inter.staticPrint();
35             
36             Inter i = new InterImpl();//可以通过使用静态方法的实现类来调用该静态方法
37             i.defaultPrint();
38             i.show();
39         }
40 }
原文地址:https://www.cnblogs.com/LZL-student/p/5971110.html