1. The format of the default method in the interface:
public default返回值类型方法名(参数列表) { }
Notes on the default method in the interface:
2. The default method It is not an abstract method, so it is not rewritten. But it can be rewritten, and keywords can be deleted during rewriting.
public can be omitted, but default cannot be omitted.
Example
1:定义一个接口MyInterface,里面有两个抽象方法: void show1(); void show2(); 2:定义接口的两个实现类: MyInterface ImplOne MyInterface ImplTwo 3:定义测试类: MyInterfaceDemo 在主方法中,按照多态的方式创建对象并使用
The above is the detailed content of What is the format of using default methods in java interface. For more information, please follow other related articles on the PHP Chinese website!