首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
若有以下程序: #include <iostream> using namespace std; class Base { int x; protected: int y; public:
若有以下程序: #include <iostream> using namespace std; class Base { int x; protected: int y; public:
admin
2010-03-29
47
问题
若有以下程序: #include <iostream> using namespace std; class Base { int x; protected: int y; public: int z; void setx(int i) { x=i; } int getx ( ) { return x; } }; class Inherit : private Base { private: int m; public: int p; void setvalue(int a,int b,int c, int d) { setx(a) ; y=b; z=c; m=d; } void display() { cout<<getx ()<<", "<<y<<", "<<z<<", "<<m<<end1; } }; int main() { Inherit A; A.setvalue(1,2,3,4); A.display(); return 0; } 程序运行后的输出结果是( )。
选项
A、1,2,3,4
B、产生语法错误
C、4,3,2,1
D、2,3,4,5
答案
1
解析
本题中,基类Base中的保护成员y和公有成员setx和getx,经过私有继承以后,称为派生类Inherit的私有成员,所以可以在派生类Inherit的函数成员中对它们进行访问。类Inherit中的函数成员setvalue和display都是公有成员,所以可以通过Inherit的对象对它们进行访问。本程序的功能是对类中各数据成员进行赋值,然后查看赋值是否正确。
转载请注明原文地址:https://kaotiyun.com/show/2Tjp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
若有以下程序#include#defineS(x)(x)*(x)#defineT(x)S(x)/S(x)+1main(){intk=3,j=2;printf("%d,%d\n",S(k+j),T(k+j));}则程序的输
下列语句组中,正确的是
有以下程序main(){inti=1;i=i^i;printf("%d\n",i);}程序运行后的输出结果是
若有以下程序#include<stdio.h>int*f(int*s,int*t){int*k;if(*s<*t){k=s;s=t;t=k;}returns;}main(){inti=3,j=5,*
有以下程序,程序运行后的输出结果是main(){intm=1,n=2,*p=&m,*q=&n,*r;r=p;p=q;q=r;printf("%d,%d,%d,%d\n",m,n,*p,*q);}
有以下程序#include#deftneN4voidfun(inta[][N],intb[]){inti;for(i=0;i
在数据库设计中,将E—R图转换成关系数据模型的过程属于
下列叙述中正确的是
若有定义语句:chars[10]=“1234567\0\0”;,则strlen(s)的值是()。
简单程序设计步骤中不包括
随机试题
诊断慢性阻塞性肺疾病最重要的条件是
工程上,常以()流体为基准,计量流体的位能、动能和静压能,分别称为位压头、动压头和静压头。
临床上氯霉素常见的毒副作用包括
桃仁的功效是
患者,女,25岁。妊娠8周,下列除哪组药外,均不宜服用
环境影响评价的工作程序可以分为三个主要阶段( )。
神经衰弱疲劳具有()。
Haveyoueverbeenannoyedwithyourselfwhenyou【C1】______somethingimportant?Maybeyouthinkyouhaveabadmemory.Doyoukn
糖尿病微血管病变的病理特点是
A、She’sunimpressedbywhatthemantoldher.B、Shedoubtsshecanaffordit.C、Shedoesn’tthinkit’ssuitableforher.D、She’s
最新回复
(
0
)