知识点记录-JAVA8常用语法特点默认接口方法
练习默认接口方法
package com.test.jdk8;
interface DefaultInterface {
int testGet(int a);
default int get(int c) {
return c + 1;
}
}
public class TestDefaultInterfaceMethod implements DefaultInterface {
public static void main(String[] args) {
TestDefaultInterfaceMethod defaultInterface = new TestDefaultInterfaceMethod();
System.out.println("testGet=" + defaultInterface.testGet(2));
System.out.println("get=" + defaultInterface.get(5));
}
@Override
public int testGet(int a) {
return DefaultInterface.super.get(a);
//或
//return get(a);
}
}