有如下程序:
nclude<iostream>
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{rgturn“Dog”;}
char*getVoice()const{retum“Woof”;}
};
void type(Animal&A){cout<<a.getType();}
void speak(AnimalA){cout<<a.getVoice();}
int main(){
Dog d.type(D);tout<<“speak”;speak(D);cout<<endl;
return 0;
}
运行时的输出结果是【 】
第1题:
有以下程序: #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
第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题:
6、对于下面两个类的描述正确的为() class Animal { public: Animal (char*) ; virtual void eat() = 0; virtual void sleep() =0; protected: char name[10]; }; class Brid: public Animal { public: Brid (char* ); virtual void fly(); void breed(); void sleep () ; };
A.Animal为抽象类, Brid也为抽象类#B.Animal为抽象类, 所有的成员函数均为纯虚函数#C.Brid类不包含纯虚函数, 因此不是抽象类#D.若有基类指针Animal* p= new Bird(“parrot”); 执行语句p->sleep();则调用Animal::sleep()第4题:
有如下程序: #include<iostream> using namespace std; class Toy{ public: Toy(char*_n){strcpy(name,_n);count++;} ~Toy(){count--;} char*GetName( ){return name;} static int getCount( ){return count;} private: char name[10]; static int count; }; int Toy::count=0: int main( ){ Toy tl("Snoopy"),t2("Mickey"),t3("Barbie"); cout<<t1.getCount( )<<endl; return 0; } 程序的输出结果是
A.1
B.2
C.3
D.运行时出错
第5题: