单选题
C++
题号 #2254961
有以下程序:
#include<iostream>
usingnamespacestd;
classA
{private:
inta:
public:
A(inti)
{a=i;}
voiddisp()
{cout<<a<<",";));
classB
(private:
intb;
public:
B(intj)
{b=j;}
voiddisp()
{cout<<b<<",";}};
classC:publicB,publicA
{private:
intC;
public:
c(intk):A(k-2),B(k+2)
{c=k;
}
voiddisp()
{
a::disp();
B::disp();
COUt<<c<<endl;
}
};
intmain()
{
Cobj(10);
obj.disp();
return0;
}
程序执行后的输出结果是( )。
参考答案
D
答案解析
D。【解析】本题中,派生类C具有多重继承关系,所以在派生类C的构造函数中应该包含基类A和类B的成员初始化列表。
你可能感兴趣的试题
A.8,6,4,1
B.8,6,3,2
C.8,8,4,1
D.8,6.4,2
A.ofstreammyfile;myfile.open("d:ofile.txt");
B.ofstream*myfile=newofstream;myfile->open("d:ofile.txt”);
C.ofstreammyfile("d:ofile.txt");
D.ofstream*myfile=new("d:ofile.txt");