企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
转载自:https://www.runoob.com/java/java8-default-methods.html **** ```java public class Java8Tester { public static void main(String args[]){ Vehicle vehicle = new Car(); vehicle.print(); } } interface Vehicle { default void print(){ System.out.println("我是一辆车!"); } static void blowHorn(){ System.out.println("按喇叭!!!"); } } interface FourWheeler { default void print(){ System.out.println("我是一辆四轮车!"); } } class Car implements Vehicle, FourWheeler { public void print(){ Vehicle.super.print(); FourWheeler.super.print(); Vehicle.blowHorn(); System.out.println("我是一辆汽车!"); } } ``` 运行结果如下: ```shell $ javac Java8Tester.java $ java Java8Tester 我是一辆车! 我是一辆四轮车! 按喇叭!!! 我是一辆汽车! ```