day09-接口的静态方法的定义和使用
This commit is contained in:
21
day10/src/com/inmind/interface_static03/Demo03.java
Normal file
21
day10/src/com/inmind/interface_static03/Demo03.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package com.inmind.interface_static03;
|
||||
/*
|
||||
jdk8接口中添加了静态方法
|
||||
静态方法:封装接口相关的通用的功能,提供辅助工具的方法。
|
||||
|
||||
接口的静态方法定义:
|
||||
public static void method(){
|
||||
|
||||
};
|
||||
|
||||
-----------------------
|
||||
接口中的静态方法的使用:
|
||||
只能通过接口名.静态方法(参数列表)直接调用
|
||||
*/
|
||||
public class Demo03 {
|
||||
public static void main(String[] args) {
|
||||
MyInterfaceImpl myInterface = new MyInterfaceImpl();
|
||||
//myInterface.method();//错误,接口的静态方法不能通过实现类对象来调用,由于接口与类是多实现的
|
||||
MyInterface.method();
|
||||
}
|
||||
}
|
||||
8
day10/src/com/inmind/interface_static03/MyInterface.java
Normal file
8
day10/src/com/inmind/interface_static03/MyInterface.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package com.inmind.interface_static03;
|
||||
|
||||
public interface MyInterface {
|
||||
//静态方法
|
||||
public static void method(){
|
||||
System.out.println("接口中的静态方法");
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.inmind.interface_static03;
|
||||
|
||||
public class MyInterfaceImpl implements MyInterface{
|
||||
}
|
||||
Reference in New Issue
Block a user