首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include<iostream> using namespace std; class xx{ int x; public: XX(int xx=0):x(xx){} int ge
有如下程序: #include<iostream> using namespace std; class xx{ int x; public: XX(int xx=0):x(xx){} int ge
admin
2017-04-25
17
问题
有如下程序:
#include<iostream>
using namespace std;
class xx{
int x;
public:
XX(int xx=0):x(xx){}
int getX(){return x;}
};
class YY:public xx{
int y;
public:
YY(int xx,int yy):XX(xx),y(yy){}
int getV(){return getX()+y;}
};
int main(){
YY c(3,4);
cout<<c.getV()+c.getX()<<endl;
return 0;
}
运行这个程序的输出结果是( )。
选项
A、3
B、4
C、7
D、10
答案
D
解析
由于类YY公开继承自类XX,所以执行表达式c.getV()+c.getX()的值等于3+3+4=10。
转载请注明原文地址:https://kaotiyun.com/show/hmAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
在下列函数原型中,可以作为类AA构造函数的是
下面叙述正确的是
下列程序的运行结果是【 】。#include<iostream,h>classBase{public:voidf(intx){cout<<"Base:"<<x<<end1;}
下列关于成员函数特征的描述中,错误的是()。
函数模板:template<classT>Tadd(Tx,Ty){returnx+y;}下列对add函数的调用不正确的是()。
类中包含了一个静态成员函数,则main函数中和P.f1(P);语句具有同样功能的语句为【 】。#include<iostream.h>classM{
类classone在声明func成员函数时发生错误,出错原因是【 】。Classone{private:inta;
下面程序编译时发现ma[3]=9错误,其原因是【 】。#include<iostream.h>classFunArray{int*pa;//指向一个数组空间intsize;//数组元素个数public:FunA
private访问属性限制对象的成员,可以在( )中访问。
在下列关系运算中,可能改变关系中属性个数的是
随机试题
著名诗人温子升被誉为()。
“三个有利于”标准中,核心是( )
Importforthefirstthreemonthsthisyearislargerthanforthe______periodlastyear.
慢性骨髓炎的手术指征是
真人养脏汤的作用是
重量感觉阈限值的大小与相应的重量感受性高低之问的关系成()。
下列关于法的作用的说法中正确的是()。
以下选项中,符合所给图形的变化规律的是____。
康德
国有公司对其财产享有()。
最新回复
(
0
)