问题
单项选择题
有如下程序:
#include<iostream>
using namespace std;
class Base
public:
void fun() cout<<"Base::fun"<<endl;
;
class Derived: public Base
public:
void tim()
____________
cout<<"Derived:: fun"<<endl;
;
int main()
Derived d;
d.fun();
return O;
已知其执行后的输出结果为:
Base::fun
Derived::fun
则程序中下划线处应填入的语句是
A) Base.fun();
B) Base::fun();
C) Base->fun();
D) fun();
答案
参考答案:B
解析: 本题考查的知识点是继承的运用。题目中要求的两行输出结果分别在基类的成员函数fun()与派生类的成员函数fun()中给出,而主函数中只通过派生类对象d调用fun()函数,即只调用了派生类的成员函数fun()。所以,横线处应该填入对基类成员函数fun()的调用语句,此处只能使用作用域运算符“::”才能调用到基类中的同名函数,故应该选择B。