单选题 C++
题号 #2254967

有如下程序:
#include<iostream.h>
usingnamespacestd;
classBase
{
public:
Base(){cout<<"BB";f();}
voidf(){cout<<"BF";}
};
classDerived:publicBase
{
public:


Derived(){cout<<"DD";}
voidf(){eout<<"Df";}
};
intmain(){Derivedd;return0;}
执行上面的程序将输出(  )。

进入在线模考

参考答案

A

答案解析

A。【解析】本题考查类的继承和派生。派生类执行构造函数的一般次序为:首先调用基类构造函数;然后调用成员对象的构造函数;最后是派生类构造函数中的内容。题目中定义派生类对象d时,先调用基类Base的构造函数,输出BBBf,然后调用派生类Derived的构造函数,输出DD。

你可能感兴趣的试题

找试题 · 找答案 · 找资料 在线模考