首页 > 试题广场 >

下列语句哪些会出现编译错误( )

[不定项选择题]
下列语句哪些会出现编译错误(      )
  • interface MyIntf{
    void pirnt1();
    }

    interface MyIntf2{
    void pirnt1();
    }

    public class Test implements MyIntf,MyIntf2{
    public void pirnt1() {}

    public static void main(String[] args) {}
    }
  • interface MyIntf{
    int pirnt1();
    }

    interface MyIntf2{
    void pirnt1();
    }

    public class Test implements MyIntf,MyIntf2{
    public void pirnt1() { }

    public static void main(String[] args) { }
    }
  • interface MyIntf{
    void pirnt1();
    }

    public class Test{
    public static void main(String[] args) {
    MyIntf Intf = new MyIntf();
    }
    }
  • interface MyIntf{
    int pirnt1();
    }

    interface MyIntf2{
    void pirnt1();
    }

    public class Test implements MyIntf,MyIntf2{
    public int pirnt1() {}

    public static void main(String[] args) {}
    }

重写的要求

1.方法名相同.

2.参数 类型,个数,顺序相同.

3.返回值相同.(例外是 返回值具有父子类关系也可以)

3.重写方法的访问权限 ,要大于被重写方法的访问权限.

4.被static , final 修饰的方法也不可以重写 

编辑于 2023-04-05 11:30:03 回复(0)
除非实现接口的类是抽象类,否则需要实现接口的所以方法
发表于 2021-09-16 16:45:38 回复(0)