接口的一些使用总结
package demo05;
public interface MyInterfaceAbstract {
public static final int NUM= 10 ;
public abstract void method1 ( ) ;
public void method2 ( ) ;
abstract void method3 ( ) ;
void method4 ( ) ;
public default void method5 ( ) {
System. out. println ( "这是接口的默认方法" ) ;
}
public static void method6 ( ) {
System. out. println ( "这是接口的静态方法" ) ;
}
}
package demo05;
public class MyInterfaceAbstractImpl implements MyInterfaceAbstract {
@Override
public void method1 ( ) {
System. out. println ( "这是第一个方法" ) ;
}
@Override
public void method2 ( ) {
System. out. println ( "这是第二个方法" ) ;
}
@Override
public void method3 ( ) {
System. out. println ( "这是第三个方法" ) ;
}
@Override
public void method4 ( ) {
System. out. println ( "这是第四个方法" ) ;
}
}
package demo05;
public class Demo01Interface {
public static void main ( String[ ] args) {
MyInterfaceAbstractImpl impl = new MyInterfaceAbstractImpl ( ) ;
impl. method1 ( ) ;
impl. method2 ( ) ;
impl. method3 ( ) ;
impl. method4 ( ) ;
impl. method5 ( ) ;
MyInterfaceAbstract. method6 ( ) ;
System. out. println ( MyInterfaceAbstract. NUM) ;
}
}