单选题
C++
题号 #2250920
有如下程序:
#include<iostream>
usingnamespacestd;
classB{
public:
B(intxx):x(xx){++count;x+=10;}
virtualvoidshow( )const
{cout<<count<<''<<x<<endl;}
protected:
staticintcount;
private:
intx;
};
classD:publicB{
public:
D(intxx,intyy):B(XX),y(yy){++count;y+=
100;)
virtualvoidshow( )const
{cout<<count<<''<<y<<endl);
private:
inty;
};
intB::count==0;
intmain( ){
B*ptr=newD(10,20);
ptr->show( );
deleteptr;
return0;
}
运行时的输出结果是( )。
参考答案
B
答案解析
B。【解析】本题考查了类的继承。继承有3种方式,public公有、private私有和protected保护,本题都涉及了。本题中类D公有继承类B。在类B中又定义了虚函数,并且有保护类静态类型count及私有变量x。主函数中调用类D,类D又继承了类B,经过系统及调用,本题最终结果为2_120。