多选题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 i

题目
多选题
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; }

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

第1题:

1. class Super {  2. public float getNum() { return 3.0f; }  3. }  4.   5. public class Sub extends Super {  6.   7. }  Which method, placed at line6, causes compilation to fail?()  

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

正确答案:A

第2题:

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

第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题:

1. public class X (  2. public object m ()  {  3. object o = new float (3.14F);  4. object [] oa = new object [1];  5. oa[0]= o;  6. o = null;  7. return oa[0];  8. }  9. }   When is the float object created in line 3, eligible for garbage collection?()  

  • A、 Just after line 5
  • B、 Just after line 6
  • C、 Just after line 7 (that is, as the method returns)
  • D、 Never in this method.

正确答案:D

第5题:

现有:   1. class Synapse {    2.    protected int gap() { return 7; }    3. }   4.     5. class Creb extends Synapse {    6.   // insert code here   7. }    分别插入到第 6 行,哪三行可以编译?()

  • A、 int gap() { return 7; }
  • B、 public int gap() { return 7; }
  • C、 private int gap(int x) { return 7; }
  • D、 protected Creb gap() { return this; }
  • E、 public int gap() { return Integer.getInteger ("42"); }

正确答案:B,C,E

第6题:

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

第7题:

1. class Over{   2. int doIt(long x) { return 3;}   3. }   4.   5. class Under extends Over{   6. //insert code here 7. }   和四个方法:   short doIt(int y) {return 4;}   int doIt(long x,long y){return 4;}   private int doIt(Short y){ return 4;}   protected int doIt(long x){return 4;}   分别插入到第6行,有几个可以通过编译?()  

  • A、2
  • B、3
  • C、4
  • D、0
  • E、1

正确答案: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题:

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

第10题:

class BaseClass{   private float x= 1.0f;   protected void setVar (float f) {x = f;}   }   class SubClass exyends BaseClass {   private float x = 2.0f;   //insert code here  8. }   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

更多相关问题