CMS专题

单选题1. class super {  2. public float getNum() {return 3.0f;}  3. }  4.    5. public class Sub extends Super { 6.   7. }   Which method, placed at line 6, will cause a compiler error?()APublic float getNum()   {return 4.0f; }BPublic void getNum ()  { }CPub

题目
单选题
1. class super {  2. public float getNum() {return 3.0f;}  3. }  4.    5. public class Sub extends Super { 6.   7. }   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; }

如果没有搜索结果,请直接 联系老师 获取答案。
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

1. public class Target {  2. private int i = 0;  3. public int addOne() {  4. return ++i;  5. }  6. }  And:  1. public class Client {  2. public static void main(String[] args) {  3. System.out.println(new Target().addOne());  4. }  5. }  Which change can you make to Target without affecting Client?() 

  • A、 Line 4 of class Target can be changed to return i++;
  • B、 Line 2 of class Target can be changed to private int i = 1;
  • C、 Line 3 of class Target can be changed to private int addOne() {
  • D、 Line 2 of class Target can be changed to private Integer i = 0;

正确答案:D

第2题:

class super {  public int getLength()  {return 4;}  }  public class Sub extends Super {  public long getLength() {return 5;}  public static void main (String[]args)  {  super sooper = new Super ();  Sub sub = new Sub();  System.out.printIn(  sooper.getLength()+ “,” + sub.getLength()   };  }  What is the output?()  

  • A、 4, 4
  • B、 4, 5
  • C、 5, 4
  • D、 5, 5
  • E、 The code will not compile.

正确答案:E

第3题:

下列程序的执行结果是______。 include class Student { public: Student(int xx){x=

下列程序的执行结果是______。

include<iostream.h>

class Student

{

public:

Student(int xx){x=xx;}

virtual float calcTuition( );

protected:

int x;

};

float Studertt::calcTuition( )

{

return float(x*x);

}

class GraduateStudent:public Student

{

public:

GraduateStudent(int xx):Student(xx){}

float calcTuition( );

};

float Graduatestudent::calcTuition( )

{

return float(x*2);

}

void main( )

{

Student s(20);

GraduateStudent gs(30);

cout<<s.calcTuition( )<<" "<<gs.calcTuition( )<<endl;

//计算学生s和研究生gs的学费

}


正确答案:400 60
400 60

第4题:

类Test1定义如下: 1.public class Test1{ 2. public float aMethod(float a,float b){ return 0;} 3. 4.} 将以下哪种方法插入行3是不合法的。()

  • A、public float aMethod(float a, float b,float c){ return 0;}
  • B、public float aMethod(float c,float d){ return 0;}
  • C、public int aMethod(int a, int b){ return 0;}
  • D、private float aMethod(int a,int b,int c){ return 0;}

正确答案:B

第5题:

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

第6题:

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

第7题:

public class MethodOver {   public void setVar (int a, int b, float c) {   }   }   Which two overload the setVar method?()

  • A、 Private void setVar (int a, float c, int b) {}
  • B、 Protected void setVar (int a, int b, float c) {}
  • C、 Public int setVar (int a, float c, int b) (return a;)
  • D、 Public int setVar (int a, int b, float c) (return a;)
  • E、 Protected float setVar (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题:

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

第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

更多相关问题