day10-接口的默认方法的定义和使用

This commit is contained in:
2026-07-27 10:21:45 +08:00
parent beb20cf752
commit b099333123
7 changed files with 93 additions and 3 deletions
@@ -0,0 +1,23 @@
package com.inmind.interface_default02;
public class MyInterfaceImpl1 implements MyInterface{
@Override
public void method1() {
System.out.println("实现类1中method1方法");
}
@Override
public void method2() {
System.out.println("实现类1中method2方法");
}
//ctrl+o
@Override
public void method3() {
MyInterface.super.method3();//沿袭(沿用)接口中的默认功能
//也可以选择性扩展增强
System.out.println("实现类1扩展增强了method3");
}
}