day10-接口interface-私有方法的使用
This commit is contained in:
14
day10/src/com/inmind/interface_private04/Demo04.java
Normal file
14
day10/src/com/inmind/interface_private04/Demo04.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package com.inmind.interface_private04;
|
||||||
|
/*
|
||||||
|
JDK9中提供了私有方法的使用
|
||||||
|
接口的私有方法定义和使用
|
||||||
|
格式:
|
||||||
|
private 返回值类型 私有方法名(参数列表){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
作用:接口中私有方法的作用,是给接口中默认方法来调用的,也就是说私有方法是将默认方法中
|
||||||
|
相同的内容抽取出来,同时静态方法也可以做相同的操作
|
||||||
|
*/
|
||||||
|
public class Demo04 {
|
||||||
|
}
|
||||||
58
day10/src/com/inmind/interface_private04/MyInterface.java
Normal file
58
day10/src/com/inmind/interface_private04/MyInterface.java
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
package com.inmind.interface_private04;
|
||||||
|
|
||||||
|
public interface MyInterface {
|
||||||
|
//定义3个默认方法
|
||||||
|
public default void methodD1(){
|
||||||
|
/*System.out.println("1");
|
||||||
|
System.out.println("2");
|
||||||
|
System.out.println("3");*/
|
||||||
|
methodD4();
|
||||||
|
}
|
||||||
|
default void methodD2(){
|
||||||
|
/*System.out.println("1");
|
||||||
|
System.out.println("2");
|
||||||
|
System.out.println("3");*/
|
||||||
|
methodD4();
|
||||||
|
}
|
||||||
|
default void methodD3(){
|
||||||
|
/*System.out.println("1");
|
||||||
|
System.out.println("2");
|
||||||
|
System.out.println("3");*/
|
||||||
|
methodD4();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void methodD4(){
|
||||||
|
System.out.println("1");
|
||||||
|
System.out.println("2");
|
||||||
|
System.out.println("3");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static void methodS4(){
|
||||||
|
System.out.println("1");
|
||||||
|
System.out.println("2");
|
||||||
|
System.out.println("3");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//定义3个静态方法
|
||||||
|
public static void methodS1(){
|
||||||
|
/*System.out.println("1");
|
||||||
|
System.out.println("2");
|
||||||
|
System.out.println("3");*/
|
||||||
|
methodS4();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void methodS2(){
|
||||||
|
/*System.out.println("1");
|
||||||
|
System.out.println("2");
|
||||||
|
System.out.println("3");*/
|
||||||
|
methodS4();
|
||||||
|
}
|
||||||
|
static void methodS3(){
|
||||||
|
/*System.out.println("1");
|
||||||
|
System.out.println("2");
|
||||||
|
System.out.println("3");*/
|
||||||
|
methodS4();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user