gitee
package com.xcrj.java8.defaultfunc;
public class Test1 {
public static void main(String[] args) {
MyInterface.staticFunc();
ImplClass implClass=new ImplClass();
implClass.defaultFunc();
MyInterface implClass1=new ImplClass1();
implClass1.defaultFunc();
ImplClass2 implClass2=new ImplClass2();
implClass2.defaultFunc();
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
package com.xcrj.java8.defaultfunc;
public interface MyInterface {
static void staticFunc(){
System.out.println("static MyInterface");
}
default void defaultFunc(){
System.out.println("default MyInterface");
}
}
package com.xcrj.java8.defaultfunc;
public class ImplClass implements MyInterface {
}
package com.xcrj.java8.defaultfunc;
public class ImplClass1 implements MyInterface{
@Override
public void defaultFunc(){
System.out.println("ImplClass1");
}
}
package com.xcrj.java8.defaultfunc;
public class MyClass {
public void defaultFunc(){
System.out.println("MyClass defaultFunc");
}
}
package com.xcrj.java8.defaultfunc;
public class ImplClass2 extends MyClass implements MyInterface{
}
package com.xcrj.java8.defaultfunc;
public interface MyInterface2 {
default void defaultFunc(){
System.out.println("default MyInterface2");
}
}
package com.xcrj.java8.defaultfunc;
public class ImplClass3 implements MyInterface,MyInterface2 {
@Override
public void defaultFunc(){
System.out.println("MyClass3 defaultFunc");
}
}