SCJP程序员认证考试

多选题class BaseClass{  private float x= 1.0f;  protected void setVar (float f) {x = f;}  }  class SubClass extends BaseClass   {  private float x = 2.0f;  //insert code here  }   Which two are valid examples of method overriding?()AVoid setVar(float f) {x =

题目
多选题
class BaseClass{  private float x= 1.0f;  protected void setVar (float f) {x = f;}  }  class SubClass extends BaseClass   {  private float x = 2.0f;  //insert code here  }   Which two are valid examples of method overriding?()
A

Void setVar(float f) {x = f;}

B

Public void setVar(int f) {x = f;}

C

Public void setVar(float f) {x = f;}

D

Public double setVar(float f) {x = f;}

E

Public final void setVar(float f) {x = f;}

F

Protected float setVar() {x=3.0f; return 3.0f; }

参考答案和解析
正确答案: E,B
解析: 暂无解析
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

class super {   public float getNum() {return 3.0f;}   }   public class Sub extends Super {   }   Which method, placed at line 6, will cause a compiler error?()

  • A、 Public float getNum() {return 4.0f; }
  • B、 Public void getNum (){}
  • C、 Public void getNum (double d){}
  • D、 Public double getNum (float d) {retrun 4.0f; }

正确答案:B

第2题:

1. abstract class AbstractIt {  2. abstract float getFloat();  3. }  4. public class AbstractTest extends AbstractIt {  5. private float f1 = 1.0f;  6. private float getFloat() { return f1; }  7. }  What is the result?() 

  • A、 Compilation succeeds.
  • B、 An exception is thrown.
  • C、 Compilation fails because of an error at line 2.
  • D、 Compilation fails because of an error at line 6.

正确答案:D

第3题:

类A定义如下: class A { private int x=10; int getx() { return x;} } class B extends A { private int x=15; //需要覆盖getx()方法 } 在下述方法中可以在类B中覆盖getx()方法的是 ( )

A.int getx(){…}

B.int getx(float f){…}

C.float getx(){…}

D.double getx(float f){…}


正确答案:A
解析:在Java中子类的方法覆盖父类中的方法时要求两个方法的名称、返回值类型以及参数表必须相同。在本题中,选项B、D中方法的参数表不同于父类中的getx()方法的参数表;而选项C中方法的返回值类型与父类中getx()方法不同,所以选项A正确。

第4题:

Which two cause a compiler error?() 

  • A、 float[] = new float(3);
  • B、 float f2[] = new float[];
  • C、 float[] f1 = new float[3];
  • D、 float f3[] = new float[3];
  • E、 float f5[] = { 1.0f, 2.0f, 2.0f };
  • F、 float f4[] = new float[] { 1.0f. 2.0f. 3.0f};

正确答案:A,B

第5题:

abstract class abstrctIt {   abstract float getFloat ();   }   public class AbstractTest extends AbstractIt {   private float f1= 1.0f;   private float getFloat () {return f1;}   }   What is the result? ()

  • A、 Compilation is successful.
  • B、 An error on line 6 causes a runtime failure.
  • C、 An error at line 6 causes compilation to fail.
  • D、 An error at line 2 causes compilation to fail.

正确答案:C

第6题:

class One {  void foo() {}  }  class Two extends One {   //insert method here  }  Which three methods, inserted individually at line 14, will correctly complete class Two?()

  • A、 int foo() { /* more code here */ }
  • B、 void foo() { /* more code here */ }
  • C、 public void foo() { /* more code here */ }
  • D、 private void foo() { /* more code here */ }
  • E、 protected void foo() { /* more code here */ }

正确答案:B,C,E

第7题:

Given:  1. public class Method Over {  2. public void set Var (int a, int b, float c) {  3. }  4. }   Which two overload the set Var method()?

  • A、 private void set Var(int a, float c, int b) {}
  • B、 protected void set Var(int a, int b, float c) {}
  • C、 public int set Var(int a, float c, int b) {return a:}
  • D、 public int set Var(int a, int b, float c) {return a:}
  • E、 protected float set Var(int a, int b, float c) {return c:}

正确答案:A,C

第8题:

1. class BaseClass {  2. private float x = 1.of;  3. protected float getVar() { return x; }  4. }  5. class SubClass extends BaseClass {  6. private float x = 2.Of;  7. // insert code here 8. }   Which two are valid examples of method overriding when inserted at line 7?() 

  • 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; }

正确答案:B,D

第9题:

Which three are valid declarations of a float? () 

  • A、 Float foo = -1;
  • B、 Float foo = 1.0;
  • C、 Float foo = 42e1;
  • D、 Float foo = 2.02f;
  • E、 Float foo = 3.03d;
  • F、 Float foo = 0x0123;

正确答案:A,D,F

第10题:

class BaseClass{  private float x= 1.0f;  protected void setVar (float f) {x = f;}  }  class SubClass extends BaseClass   {  private float x = 2.0f;  //insert code here  }   Which two are valid examples of method overriding?()        

  • A、 Void setVar(float f) {x = f;}
  • B、 Public void setVar(int f) {x = f;}
  • C、 Public void setVar(float f) {x = f;}
  • D、 Public double setVar(float f) {x = f;}
  • E、 Public final void setVar(float f) {x = f;}
  • F、 Protected float setVar() {x=3.0f; return 3.0f; }

正确答案:C,E

更多相关问题