day10-接口的静态方法的定义和使用
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package com.inmind.interface_static03;
|
||||
/*
|
||||
接口中的静态方法的使用:
|
||||
只能通过接口名.静态方法(参数列表)直接调用
|
||||
*/
|
||||
public class Demo03 {
|
||||
public static void main(String[] args) {
|
||||
//调用静态方法(接口名.静态方法(参数列表)直接调用)
|
||||
MyInterface.method1();
|
||||
MyInterface.method2();
|
||||
//能不能使用对象来强制调用???绝对不行,只能通过定义静态方法的接口调用!!!!
|
||||
/*MyInterfaceImpl myInterface = new MyInterfaceImpl();
|
||||
myInterface.method1();
|
||||
MyInterfaceImpl.method1();*/
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.inmind.interface_static03;
|
||||
/*
|
||||
jdk8接口中添加了静态方法
|
||||
静态方法:封装接口相关的通用的功能,提供辅助工具的方法。
|
||||
|
||||
接口的静态方法定义:
|
||||
public static void method(){
|
||||
|
||||
};
|
||||
*/
|
||||
public interface MyInterface {
|
||||
//静态方法
|
||||
public static void method1(){
|
||||
System.out.println("接口中的静态方法method1");
|
||||
}
|
||||
|
||||
static void method2(){
|
||||
System.out.println("接口中的静态方法method2");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.inmind.interface_static03;
|
||||
|
||||
public class MyInterfaceImpl implements MyInterface{
|
||||
//静态方法能重写吗?不能
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user