首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
下面程序的执行结果为 #include"iostream" using namespace std; class A { int a; public:
下面程序的执行结果为 #include"iostream" using namespace std; class A { int a; public:
admin
2013-05-30
45
问题
下面程序的执行结果为 #include"iostream" using namespace std; class A { int a; public: void Seta(int x){a=x;} void Display_a( ){cout<<a<<endl;} }; class B { int b; public: void Setb(int x){b=x;} void Dispaly-b( ) {cout<<b<<endl;} }; class C:public A,private B { private: int c; public: void Setc(int x,int y,int z) {c=z;Seta(x);Setb(y);} void Display_c( ){ cout<<c<<endl;} }; ①void main( ) ② { ③ C cc; ④ cc.Seta(1); ⑤ cc.Display_a( ); ⑥ cc.Setc(2,2,3); ⑦ cc.Dispaly-b( ); ⑧ cc.Display_c( ); }
选项
A、输出为2 2 3
B、有错误在第5行
C、输出为1 2 3
D、有错误在第7行
答案
8
解析
private继承不能调用Display_b函数, public继承可以调用基类中非private成员。注意:类的继承方式public,protected和private的区别。
转载请注明原文地址:https://kaotiyun.com/show/lQNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
可以用p.a的形式访问派生对象p的基类成员,其中a是______。
以下程序段的输出结果是______。#include<iostream.h>voidmain(){char*p[5]={"ABCD","EF","GHI","JKL","MNOP"};char**q=p;
下面程序的输出结果为【】。#inclUde<iostream.h>voidmain(){inta;int&b=a;//变量引用b=10;cout<<"a="<<a<<endl
在调用一个函数的过程中可以直接或间接地调用该函数,这种调用称为【】调用,该函数称为【】函数。
阅读以下程序:#include<iostream.h>classkk{intm;public:staticintn;kk(){m=0;1voidsetvalu
对关系S和关系R进行集合运算,结果中既包含S中元组也包含R中元组,这种集合运算称为()。
下面函数的作用是【】。intindex(intx,inta[],intn){for(inti=0;i<n;i++){if(a[i]==x)
下面程序的输出结果是()。#include<iostream>usingnamespacestd;voidmain(){inti=1;while(i<=8)if
请定义一个函数名为A,返回值为int,没有参数的纯虚函数的定义是,【】。
通过指针访问类对象成员的方法是______。
随机试题
简述汇率波动受哪些因素的影响。
支气管哮喘发作时动脉血气分析PaO2降低,PaCO2正常或升高,最可能的表示是
迄今为止发展最快、渗透性最强、应用关键技术最广泛的行业是( )。
财务限制条款是防止公司的财务状况出现恶化的限制条款,其内容包括()。
有价证券的二级市场是指()。
“穿衣服、系鞋带”属于独立自主性教育中()的基本内容。
Youshouldspendnomorethan20minutesonthistask.Youandyourfamilyhaddinnerinarestaurantafewnightsago.The
WhenMr.Greenwasawayonbusiness,hisneighborgavehiswifea(n)______withthehousework.
Lemonadeisa(n)______drink.Lemonadeisnotanewdrink.It______.
Tomwastheonlyoneofthestudentswho________namedOutstandingStudent.
最新回复
(
0
)