• java的 interface 可以有方法体


    在interface 中的方法也可以有方法体

    public interface InterfaceMethod {
    
        public static int ID=1;//默认为 final static 即常量
        //public InterfaceMethod(){}
        public static void say(){
            
            System.out.println("aa");
        }
        public default void sayhi(){
            System.out.println("aa");
        }
        public void sayBye();
    }
    InterfaceMethod
    public class IntefaceMethodImpl implements InterfaceMethod {
        @Override
        public void sayBye() {
            // TODO Auto-generated method stub
            System.out.println("syabye--");
        }
    }
    IntefaceMethodImpl
    public class TestInterfaceMethod {
        public static void main(String[] args) {
            InterfaceMethod ifm=new IntefaceMethodImpl();
            ifm.sayBye();
            ifm.sayhi();
            //ifm.ID=3;
            System.out.println(ifm.ID);
            System.out.println(InterfaceMethod.ID);
            InterfaceMethod.say();
            //IntefaceMethodImpl.say(); 错误
        }
    }
    测试
  • 相关阅读:
    RPC(简单实现)
    观察者模式
    自省(Introspector)
    Mybatis学习笔记
    Nginx
    AJAX跨域
    手写Tomcat
    监听器模式
    回调
    Temporal Segment Networks
  • 原文地址:https://www.cnblogs.com/m01qiuping/p/6407546.html
Copyright © 2020-2023  润新知