问题 填空题

如下程序的输出结果是______。
#include<iostream>
using namespace std;
class Pet
char name[10];
public:
Pet(char*nanle)strcpy(this->name,name);
const char*getName( )constreturn name;
virtual void call( )eonst=0;

class Dog:public Pet
public:
Dog(char*name):Pet(name)
void call( )eonstcout<<"汪汪叫";

class Cat:public Pet
public:
Cat(char*name):Pet(name)
void call( )consteout<<"喵喵叫";

int main( )
Pet*petl=new Dog("哈克"),*pet2=new Cat("吉米");
eout<<petl->getName( );petl->call( );eout<<endl;
cout<<pet2->getName( );pet2->call( );eout<<endl;
return 0;

答案

参考答案:哈克汪汪叫 吉米喵喵叫

解析: petl、pet2首先调用继承自基类的常成员函数getName( ),分别打印传人的字符实参;然后调用各自派生类的常成员函数call( ),打印出“汪汪叫”和“喵喵叫”。

选择题
单项选择题