接口组成更新
![在这里插入图片描述](https://img-blog.csdnimg.cn/28150910f5f4406b855a58dde805c946.png)
默认方法
![在这里插入图片描述](https://img-blog.csdnimg.cn/831e42a58f844c698aeab0f24b38d48d.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA6Zi_54Kz55qE5peF56iL,size_20,color_FFFFFF,t_70,g_se,x_16)
public interface MyInterface {
void show1();
void show2();
default void show3(){
System.out.println("show3");
}
}
class MyInterfaceImplOne implements MyInterface{
@Override
public void show1() {
System.out.println("One show1");
}
@Override
public void show2() {
System.out.println("One show2");
}
}
class MyInterfaceImplTwo implements MyInterface,MyInterfaceSon{
@Override
public void show1() {
System.out.println("Two show1");
}
@Override
public void show2() {
System.out.println("Two show2");
}
@Override
public void show3() {
System.out.println("Two show3");
}
}
public class MyInterfaceDemo {
public static void main(String[] args) {
MyInterface my = new MyInterfaceImplOne();
my.show1();
my.show2();
my.show3();
MyInterface my2 = new MyInterfaceImplTwo();
my2.show1();
my2.show2();
my2.show3();
}
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/e22d7573a3ad44b1b49f0c67ce5b4b38.png)
静态方法
![在这里插入图片描述](https://img-blog.csdnimg.cn/dcac19115f28405c8bbf29509a64a92f.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA6Zi_54Kz55qE5peF56iL,size_20,color_FFFFFF,t_70,g_se,x_16)
public interface Flyable {
public static void test() {
System.out.println("Flyable中的静态方法执行了");
}
}
public interface Inter {
void show();
default void method(){
System.out.println("Inter中的默认方法");
}
public static void test(){
System.out.println("Inter重中的静态方法");
}
}
class InterImpl implements Inter,Flyable{
@Override
public void show() {
System.out.println("show方法");
}
}
public class InterDemo {
public static void main(String[] args) {
Inter i = new InterImpl();
i.show();
i.method();
Inter.test();
Flyable.test();
}
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/ae8a737a832b463a9e47590511ef4716.png)
私有方法
![在这里插入图片描述](https://img-blog.csdnimg.cn/cece25f5e4ec43a5b694f3bb1cafe4ec.png)
public interface Inter {
private void show() {
System.out.println("初级工程师");
System.out.println("中级工程师");
System.out.println("高级工程师");
}
private static void method() {
System.out.println("初级工程师");
System.out.println("中级工程师");
System.out.println("高级工程师");
}
default void show1(){
System.out.println("show1开始执行");
show();
System.out.println("show1结束执行");
}
default void show2(){
System.out.println("show2开始执行");
show();
System.out.println("show2结束执行");
}
static void method1(){
System.out.println("method1开始执行");
method();
System.out.println("method1结束执行");
}
static void method2(){
System.out.println("method2开始执行");
method();
System.out.println("method2结束执行");
}
}
class InterImpl implements Inter{
}
public class InterDemo {
public static void main(String[] args) {
Inter i = new InterImpl();
i.show1();
System.out.println("---------------");
i.show2();
System.out.println("---------------");
Inter.method1();
System.out.println("---------------");
Inter.method2();
}
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/71eabf0332d34e5bab510cdf1b5ddb88.png)