Public float getNum() {return 4.0f; }
Public void getNum (){}
Public void getNum (double 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
第2题:
有如下程序:#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
第3题:
有如下程序: #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
第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?()
第5题:
有以下程序: #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
第6题:
下列程序的执行结果是______。
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的学费
}
第7题:
有如下程序: #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
第8题:
有如下程序: #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
第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?()
第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?()