java——接口应用

2019年2月16日11:23:48 发表评论 980 views
/**
 * Created by xabcd on 2019/2/16.
 */

    interface A
    {
        int i = 10;
        public void sayI();
    }
    interface E
    {
        int x = 40;
        public void sayE();
    }
    interface B extends A,E{
        int j = 20;
        public void sayJ();
    }
    class C implements B {//此类实现了B接口,所以要覆写ABE中全部的抽象方法
        public void sayI()

        {
            System.out.println("i=" + i);
        }

        public void sayJ()

        {
            System.out.println("j=" + j);
        }

        public void sayE()

        {
            System.out.println("e=" + x);
        }
    }








/**
 * Created by xabcd on 2019/2/16.
 */
public class test_jiekou
{
    public static void main(String[] args)
    {
        C c = new C();
        c.sayI();
        c.sayJ();
    }
}


结果:
i=10
j=20

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: