• 2022-05-31
    现有如下代码 1: class Super{ 2: public float getNum(){return 3.0f;} 3: } 4: public class Sub extends Super{ 5: 6: } 在第5行加入下列哪行代码后会导致程序编译错误
    A: public float getNum(){return 4.0f;}
    B: public void getNum(){}
    C: public void getNum(double d){}
    D: public double getNum(float d){return 4.0d;}
  • B

    举一反三

    内容

    • 0

      下列代码中,将引入编译错误的行是1 public class Exercise{2 public static void main(String args[]){3 float f = 0.0 ;4 f = f + 1.0 ;5 }6 }

    • 1

      Which two are valid examples of method overriding?() A:  float getVar() {return x:} B:  public float getVar() {return x; } C:  public double getVar() {return x; } D:  protected float getVar() {return x; } E:  public float getVar(float f) {return f;}

    • 2

      下列选项中,( )代码替换源文件Com.java中的【代码】不会导致编译错误。public interface com{int M=200;int f();}class ImpCom implements Com{【代码】} A: public int f( ){return 100+M;} B: int f( ){return 100;} C: public double f( ){return 2.6;} D: public abstract int f( );

    • 3

      如下代码:public class X {public X aMethod() { return this;}}public class Y extends X { }哪两个方法能加到Y类的定义中? A: public void aMethod(String s) {} B: public void aMethod() {} C: private Y aMethod() { return null; } D: public X aMethod() { return new Y(); } E: private void aMethod() {}

    • 4

      下列程序中注释的那个代码是错误的? abstract class Takecare{ protected void speakHello() {} public abstract static void cry(); static int f(){return 0;} abstract float g(); } A: protected void speakHello() {} B: public abstract static void cry(); C: static int f(){return 0;} D: abstract float g();