有如下程序:
#include<iostream>
using namespace std;
class Instrument{
public:
virtual void Display()=0;
};
class Piano:public Instrument {
public:
void Display(){/*函数体程序略*/}
};
int main(){
Instrument s;
Instrument *p=0;
//…;
return 0;
}
下列叙述中正确的是
A.语句“Instrument *p=0;”编译时出错
B.语句“Instrument s;”编译时出错
C.类Piano中的Display函数不是虚函数
D.类Instrument是一个虚基类
第1题:
第2题:
下面程序的运行结果是( )。 #include<iostream> using namespace std; class A { public: virtual~A() { cout<<"call A::~A()"<<endl;} }; class B:public A { char * p; public: B(int i) { p=new char[i];} ~B() { delete(p); cout<<"call B::~B()"; } }; void main() { A * a=new B(8); delete a; }
A.call B::~B()call A::~A()
B.call B::~B()
C.call A::~A()
D.call A::~A()call B::~B()
第3题:
若有以下程序: #include<iostream> using namespace Std; Class Base {public: Base() {x=0;} int x;}; class Derivedl:virtua1 public Base {public: Derived1() {x=10;}}; class Derived2:virtual1 public Base {public: Derived2()
A.20
B.30
C.10
D.0
第4题:
有以下程序: #include <iostream> using namespace std; class BASE { private: char c; public: BASE(char n):c(n);{} virtual~BASE() { cout<<c; } }; class DERIVED:public BASE { char c; p
A.XY
B.YX
C.X
D.Y
第5题:
请将如下程序补充完整,使得输出结果为:bbaa。
include<iostream>
using naluespace std;
class A{
public:
______{eout<<"aa";}
};
class B:public A{
public:
~B( ){eont<<"bb";}
};
int ulain( ){
B*P=new B;
delete P;
return 0;
}
第6题:
有如下程序: #include<iostream>#include<iosream> using namespace std; class BASE{ char c; public; BASE(char n):c(n){} virtual ~ BASE(){cout<<c;} }; class DERIVED; public BASE{ char c; public: DERIVED (char n): BASE (n+1)
A.XY
B.YX
C.X
D.Y
第7题:
下面程序的结果是 #include<iostream.h> class A { public: A( ) {cout<<"construtA"<<endl;} virtual~A( ) {cout<<"destructA"<<endl;}}; class B:public A {}; class C:public A {}; c
A.constructA destructA
B.constructA constructA destructA destructA
C.constructA constructA constructA destructA destructA destructA
D.constructA onstructA constructA constructA destructA destructA destructA destructA
第8题:
有如下程序: #include<iostream> using namespace std; class Instrument{ public: virtual void Display=0; }; class Pian0:public Instrument} public: void Display{/*函数体略*/} }; intmain{ Instrument S; Instrument*P=0: //…; return 0; } 下列叙述中正确的是( )。
A.语句“Insturment*P=0;”编译时出错
B.语句“Instnunent s;”编译时出错
C.类Pian0中的Display函数不是虚函数
D.类Instrument是一个虚基类
第9题:
下面程序的结果是 #include<iostream.h> class A { public: A(){cout<<"construtA" <<endl;} virtual ~A() {cout << "destructA" <<endl;}}; class B:public A { }; class C:public A { }; class D:public B,public C { }; void main() { Dd;}
A.constructA
B.constructA
C.constmctA
D.constmctA destructA constructA constmctA constructA destructA constructA constructA destructA destructA constructA destructA dest