题目内容

有如下程序:#includeusing 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. 语句“Insturment *p=0;”编译时出错
B. 语句“Instruments;”编译时出错
C. 类Piano中的Display函数不是虚函数
D. 类Instrument是一个虚基类

查看答案
更多问题

有如下程序:#include#includeusing namespace std;class Book{public:Book(char* t=""){strcpy(title, t); }___________________private:char title[40];};class Novel: public Book {public:Novel(char *t=""): Book(t){}char *Category() const { return "文学"; }};int main(){Book *pb;pb=new Novel();cout<Category();delete pb;return 0;}若程序运行时输出结果是“文学”,则划线处缺失的语句是 。

A. char* Category();
B. char*Category() const;
C. virtual char*Category() const;
D. virtual char*Category() const=0;

以下程序运行结果中第一行到第三行分别是 、 和。#includeusing namespace std;class Base{int x;public:Base(int b): x(b){}virtual void display(){cout<display();return 0;}

有如下程序:#include using namespace std;class Animal{public:virtual char* getType()const { return "Animal";}virtual char* getVoice()const { return "Voice";}};class Dog: public Animal {public:char* getType ( ) const {return "Dog";}char* getVoice ( ) const {return "Woof";}};void type(Animal &a) {cout<

如下程序运行时的输出结果是 。#includeusing namespace std;class Base{public:Base(){ }virtual void f(){cout<<"A";}};class D1: public Base {public:D1(){ }virtual void f() const{cout<<"B";}};class D2: public D1 {public:virtual void f(){cout<<"C";}};void fun(Base &b){ b.f(); }int main(){Base b; D1 d1; D2 d2;fun(b);fun(d1);fun(d2);b.f();d1.f();d2.f();return 0;}

答案查题题库