java中多重继承组合接口存在命名冲突

来源:互联网 发布:单片机isp 编辑:程序博客网 时间:2024/05/22 03:07
package interfacetest;/** * 继承组合接口方法名字冲突 */public class InterfaceCollision {    public static void main(String[] args) {        C1 c1 = new C1();        C2 c2 = new C2();        C3 c3 = new C3();        C4 c4 = new C4();        System.out.println(c2.f(1));        System.out.println(c4.f());    }}interface I1 {    void f();}interface I2 {    int f(int i);}interface I3 {    int f();}class C1 {    public int f() {        return 1;    }}class C2 implements I1, I2 {    @Override    public void f() {    }    @Override    public int f(int i) {        return 1;    }}class C3 extends C1 implements I2 {    @Override    public int f(int i) {        return 3;    }}class C4 extends C1 implements I3 {}//class C5 extends C1  implements I1{//实现的方法和积累方法命名相同,但方法的返回值不一样。//    int f(){//        return 0;//    }//}////interface I4 extends I1 , I3{//重写的方法名相同,但是返回值不同。////    @Override//    void f();//}

因为他们的方法名都相同,但是返回值不同,并不能实现方法重载。所以不能实现多重继承和组合接口。