D. 派生类和它的基类中出现同名函数时,将可能出现二义性 C++类体系中,能被派生类继承的是( )。
A.构造函数 B.虚函数 C.析构函数 D.友元函数 设有基类定义: class Cbase
{ private: int a; protected: int b; public: int c; };
派生类采用何种继承方式可以使成员变量b成为自己的私有成员( ) A. 私有继承 B.保护继承
C. 公有继承 D.私有、保护、公有均可 关于虚函数的描述中,( )是正确的。
A. 虚函数是一个静态成员函数 B. 虚函数是一个非成员函数
C. 虚函数既可以在函数说明时定义,也可以在函数实现时定义 D. 派生类的虚函数与基类中对应的虚函数具有相同的参数个数和类型 下列关于动态联编的描述中,错误的是()。 A.动态联编是以虚函数为基础
B.动态联编是运行时确定所调用的函数代码的
C.动态联编调用函数操作是指向对象的指针或对象引用 D.动态联编是在编译时确定操作函数的 下面4个选项中,( )是用来声明虚函数的。
A.virtual B.public C.using D.false 关于纯虚函数和抽象类的描述中,错误的是( )。 A.纯虚函数是一种特殊的虚函数,它没有具体的实现 B.抽象类是指具体纯虚函数的类
C.一个基类中说明有纯虚函数,该基类派生类一定不再是抽象类 D.抽象类只能作为基类来使用,其纯虚函数的实现由派生类给出 编译时的多态性可以通过使用( )获得。
A.虚函数和指针 B.重载函数和析构函数 C.虚函数和对象
三、填写程序运行结果(每小题4分,共20分)以下程序的输出结果为 #include
cout<<”k=”<< k< 下面程序的运行结果为: #include D.虚函数和引用 using namespace std; void main() { int i,j,m=0,n=0; for(i=0;i<2;i++) for(j=0;j<2;j++) if(j>=i) m=1;n++; cout< 执行这个程序段输出字符*的个数是 #include static int c=3; b++;c++; return(a+b+c); } void main( ) {int a=2,I; for(I=0;I<3;I++) cout< 下面程序的运行结果为: #include public: Obj(){i++;} ~Obj(){i--;} static int getVal(){return i;} }; int Obj::i=0; void f (){Obj ob2;cout< Obj*ob3=new Obj;cout< 下面程序运行结束后,k的值为_____。 #include 下面程序的运行结果为: #include class C1{ public: ~C1(){ cout<<1; } }; class C2: public C1{ public: ~C2(){ cout<<2; } }; int main(){ C2 cb2; C1 *cb1; return 0; } 下面程序的运行结果为: #include virtual void funcl(){cout<< “A1”;} void func2(){cout<< “A2”;} }; class B: public A{ public: void func1(){cout<< “B1”;} void func2(){cout<< “B2”;} }; int main(){ A*p=new B; p->funcl(); p->func2(); return 0; 以下程序的输出结果为 #include cout< cout< int add(int x,int y); { return x+y; } 程序的输出结果为 。 #include using namespace std; void main() { int i=0,x=0,y=0; do{ ++i; if(i%2!=0) {x=x+i;i++;} y=y+i++; }while(i<=7); cout<<“x=”< 以下程序的输出结果为 。 int x1=30, x2=40; void main() { int x3=10, x4=20; int sub(int x, int y); } sub(x3, x4); sub(x2, x1); cout< sub(int x, int y) { x1=x; x=y; y=x1; } 以下程序的输出结果为 #include static int k; public: Csample( ); void Display( ); }; int Csample::k=0; Csample::Csample( ) { i=0; k++; } void Csample::Display( ) { cout<<\void main( ) { Csample a,b; a.Display( ); b.Display( ); } 以下程序的输出结果为 。 #include Point(int x1=0,int y1=8){x=x1;y=y1;} ~Point(){cout<<\ }; void main() {Point a; Point b(10,10); } 以下程序的输出结果为 。 #include using namespace std; class A{ public: virtual void funcl(){cout<< “A1”;} void func2(){cout<< “A2”;} }; class B: public A{ public:
相关推荐: