首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include<iostream> using namespace std; class A { public: A(int i){x=i;} void dispa(){cout<<x<<’,’;} private: int x: }; c
有如下程序: #include<iostream> using namespace std; class A { public: A(int i){x=i;} void dispa(){cout<<x<<’,’;} private: int x: }; c
admin
2015-11-24
25
问题
有如下程序:
#include<iostream>
using namespace std;
class A
{
public:
A(int i){x=i;}
void dispa(){cout<<x<<’,’;}
private:
int x:
};
class B:public A
{
public:
B(int i):A(i+10){x=i;}
void dispb(){dispa();cout<<x<<endl;}
private
int x;
};
int main()
{
B b(2);
b.dispb();
return 0;
}
运行时输出的结果是( )。
选项
A、10.2
B、12,10
C、12,2
D、2,2
答案
C
解析
此题考查的是派生类的构造。主函数中,首先声明B类的对象b,执行进入B的构造函数B(int i)再接着执行A的构造函数A(int i)。形参i为12,x被赋值12;通过对象b调用其成员函数dispb(),输出结果12;接着执行函数dispb()的第2条语句输出2,然后主函数结束。
转载请注明原文地址:https://kaotiyun.com/show/UlNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
若有以下程序段:#include<iostream>usingnamespacestd;intmain(){char*p="abcdefgh",*r;long*q;
以下程序的输出结果是#include<iostream.h>voidmain(){charx=040;cout<<(X<<1);}
有如下程序#include<iostream.h>voidmain(){charch[2][5]={"6937","8254"},*p[2];inti,j,s=0;
设有程序段intk=10;while(k=0)k=k-1;则下面描述中正确的是
以下程序的执行结果为【】。 #include<iostream> usingnamespacestd; classbase { public: virtualvoidwho() { cout<<
以下程序的输出结果是【】。 #include<iostream.h> voidmain() { inta=0; a+=(a=8); cout<<a; }
若有说明:int[3][4]={0};则下面叙述正确的()。
下列关于运算符重载不正确的是
多态性指的是()。
如果不使用多态机制,那么通过基类的指针虽然可以指向派生类对象,但是只能访问从基类继承的成员。下列程序没有使用多态机制,其输出结果是______。#include<iostream>usingnamespacestd;class
随机试题
男性,50岁,机械性肠梗阻入院,出现最早和最主要的病理生理改变是
射血分数是指每搏输出量占心室舒张末期容积量的百分比,正常成年人安静时的射血分数约为()。
证券公司从事中间介绍业务应当与期货公司签订书面委托协议,该书面委托协议应载明()。Ⅰ.介绍业务的范围Ⅱ.执行期货保证金安全存管制度的措施Ⅲ.介绍业务对接规则Ⅳ.客户投诉的接待处理方式
除非被授权,秘书不得拆开写明“亲启”或标有“机密”记号的信件。()
根据资料,回答以下问题。2012年对东盟的货物出口额占总出口额的比重为:
中断及中断处理是计算机系统的重要功能,下述哪个可能成为中断源? Ⅰ.输入输出设备 Ⅱ.数据通道 Ⅲ.时钟 Ⅳ.软件
Icouldnotaffordtorentahouselikethat,_________it.
Ofthetwolectures,(thefirst)wasbyfar(thebestone),partlybecausethepersonwhodelivered(it)had(such)apleasantv
Beforediscussingtheeffectofdeflationandinflationonthedistributionofincome,itwillbeusefultodefinetheseterms.
WhoLives?WhoDies?WhoDecides?A)SomehavecalleditaRighttoDiecase.OthershavelabeleditaRighttoLivecase.Onegr
最新回复
(
0
)