CMS专题

单选题class super {   public float getNum() {return 3.0f;}   }   public class Sub extends Super {   }   Which method, placed at line 6, will cause a compiler error?()APublic float getNum() {return 4.0f; }BPublic void getNum (){}CPublic void getNum (double d)

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

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

第1题:

有以下程序: float f1(float n) { return n*n; } float f2(float n) { return 2*n; } main() {float(*p1)(float),(*p2)(float),(*t)(float),y1,y2; p1:f1; p2=f2; y1=p2(p1(2.0)); t=p1; p1=p2; p2=t; y2=p2(p1(2.0)); printf("%3.0f,%3.0f\n",y1,y2); } 程序运行后的输出结果是 ______。

A.8, 16

B.8, 8

C.16, 16

D.4, 8


正确答案:A
解析:题中“(*p1)(float)”定义了一个指向函数的指针变量p1,此函数的返回值是float类型。在main函数中,使得p1指向了函数f1,P2指向了函数缀。语句“y1=p2(p1(2.0));”先调用了p1函数,将其返回值4.000000传递给了f2的形参n,并使其函数返回值8.000000赋值给y1。然后在main函数中交换了p1、p2指针变量的指向,使p1指向了函数侵,p2指向了函数f1,并先调用函数f2,得到返回值4.000000,使其传递给f1函数的形参n,并带回返回值16.000000赋值给y2。在输出y1、y2时,各浮点数占3列,小数位数为0,即输出了  8,16。

第2题:

有如下程序:include usingnamespacestd:class Test{public: Test(){n+=2; ~Test(){n-

有如下程序:#include <iostream>using namespace std:class Test{public: Test() {n+=2; ~Test() {n-=3; ; static int getNum() {return n;}privaue: static int n:};int Test::n=1;int main(){ Test* p=new Test; delete p; cout<<"n="<<Test::getNum()<<end1; return 0;} 执行后的输出结果是

A.n=0

B.n=1

C.n=2

D.n=3


正确答案:A
解析:本题考核静态数据成员与静态成员函数的定义与使用方式。静态数据成员是类中所有对象共享的成员,而不是某个对象的成员.题中变量n是静态数据成员,对象对其操作的结果具有叠加作用,main函数中先定义了Test的对象*p,然后又delete p,所以对静态数据n进行了两次操作,分别是“n+=2”和“n-=3”,n的初始值是1,那么n最后的值变为0。main函数最后通过调用静态函数getNum得到n的值,并输出。

第3题:

有如下程序: include using namespace std; class Test { public

有如下程序: #include<iostream> using namespace std; class Test { public: Test(){n+=2;} ~Test(){n-=3;} static int getNum(){return n;} private: static int n; }; int Tesl::n=1 int main() { Test*p=new Test; delete p; cout<<"n="<<Tes::tgetNum()<<endl; return 0; } 执行后的输出结果是

A.n=0

B.n=1

C.n=2

D.n=3


正确答案:A
解析:本题考查构造函数和析构函数的调用。类的静态成员和成员函数是类属,不依赖于对象实例存在。

第4题:

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

第5题:

有以下程序:includeincludeusingnamespacestd;classDistance;classpoint{pub

有以下程序: #include <iostream> #include <cmath> using namespace std; class Distance; class point { public: friend class Distance; Point(int a,int B) { x=a; Y=b; } void Print() { cout<<"X= "<<X<<end1; cout<<"Y= "<<Y<<end1; } private: float X,Y; }; class Distance { public: float Dis(Point &p,Point &q); }; float Distance :: Dis(Point &p,Point &q) { float result; result=sqrt((p.X-q.X)*(p.X-q.X)+(p.Y-q.Y)*(p.Y-q.Y)); cout<<result<<end1; retUrn result; } int main() { Point p(10,10),q(10,30); Distance d; d.Dis(p,q); return 0; } 运行后的输出结果是( )。

A.10

B.30

C.0

D.20


正确答案:D
解析:本题程序通过把类Distance定义为类Point类的友元类来实现计算两点之间距离的功能。主函数中定义两个对象点p,q,然后调用对象d的成员函数Dis()计算两点之间的距离。

第6题:

下列程序的执行结果是______。 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

第7题:

有如下程序: include using namespace std;class Test {public: Test() {n+=2;} ~Tes

有如下程序: #include <iostream> using namespace std; class Test { public: Test() {n+=2;} ~Test() {n-=3;} static int getNum(){retum n;} private: static int n; }; int Test:: n=1; int main() { Test*p=new Test; delete p; cout<<"n="<<Test:: getNum()<<end1; return 0; };执行后的输出结果是______.

A.n=0

B.n=1

C.n=2

D.n=3


正确答案:A
解析:经过一次构造函数和析构函数的调用后,执行后的输出结果是A。

第8题:

有如下程序: include using namespace std; class Test{ public: Tes

有如下程序: #include<iostream> using namespace std; class Test{ public: Test() {n+=2;} ~Test() {n-=3;} static int getNum(){return n;} private: static int n; }; int Test::n=1; int main() { Test*p=new Test; delete p; cout<<"n="<<Test::getNum()<<endl; return 0; } 执行后的输出结果是( )。

A.n=0

B.n=1

C.n=2

D.n=3


正确答案:A
解析:语句Test*p=new Test;会调用类的构造函数Test() {n+=2;},使n的值由原来的1变为3,然后delete p调用类的析构函数~Test() {n-=3;},因为n是static型变量,所以会在3的基础上减 3,使得输出结果为0。

第9题:

public class Person {  private String name, comment;  private int age;  public Person(String n, int a, String c) {  name = n; age = a; comment = c;  }  public boolean equals(Object o) {  if(! (o instanceof Person)) return false;  Person p = (Person)o;  return age == p.age && name.equals(p.name);  }  }  What is the appropriate definition of the hashCode method in class Person?() 

  • A、 return super.hashCode();
  • B、 return name.hashCode() + age * 7;
  • C、 return name.hashCode() + comment.hashCode() /2;
  • D、 return name.hashCode() + comment.hashCode() / 2 - age * 3;

正确答案:B

第10题:

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

更多相关问题