单选题 C++
题号 #2254850

有如下程序:
#included<iostream>
usingnamespacestd;
classTestClass
{inta;
pubIic:
TestClass(intx){a=x;}
voidshow(){cout<<a;)};
classTestClassl:publicTestClass
{intb;
public:
TestClassl(inti):TestClass(i+1),b(i){}
voidshow(){cout<<b;)};
intmain()
{TestClassb(5),*P;
TestClassld(1):
p=&d;
p->show();
return0;}
该程序运行后的打印结果是(  )。

进入在线模考

参考答案

D

答案解析

D。【解析】TestClass为TestClass1的基类,在主函数main中定义TestClass对象b,*P。TestClass1对象d,P指向d,调用其show函数。“TestClass(inti):TestClass(i+1),b(i){}”语句中的TestClass基类参数为2,所以show输出2。

你可能感兴趣的试题

A.Volumeoperator-(double,double);
B.doubleVolume::operator-(double);
C.VolumeVolume::operator-(Volume);
D.Volumeoperator-(Volume);
A.XB::XB(inta,intb):x(a),y(b){}
B.XB::XB(inta,intb):XA(a),y(b){}
C.XB::XB(inta,intb):x(a),XB(b){}
D.XB::XB(inta,intb):XA(a),XB(b){}
找试题 · 找答案 · 找资料 在线模考