A-A+

有如下程序: #include<iost earn> using namespace std

2022-08-05 20:28:19 问答库 阅读 171 次

问题详情

有如下程序: #include<iost earn> using namespace std; class TestClass{ protected: TestClass(){cout<<"x";} TestClass(char C) {cout<<c;} }; class TestClass1:public TestClass { public: TestClass1(char C) {Cout<<c;) }; int main(){ TestClass1 d1("y"); return 0; } 执行这个程序,屏幕上将显示输出()。
A.y
B.yx
C.xy
D.yy请帮忙给出正确答案和分析,谢谢!

参考答案

正确答案:C
解析:程序中的类TestClass为基类,TestClass1为TestClass的派生类。由main主函数入手,定义TestClass1类型的对象d1,参数值为'y'。TestClass1类继承TestClass,所以主函数中“TestClass1 d1('y');”语句首先调用调用基类中的“TestClass(){cout<<'x';)”输出x,然后调用“TestClass1(char C) {cout<<c;}”输出y,即答案为“xy”。

考点:程序