首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
下列程序的输出结果是【 】。 #include <iostream> using namespace std; class base { public: int n; base(iht x) {n=
下列程序的输出结果是【 】。 #include <iostream> using namespace std; class base { public: int n; base(iht x) {n=
admin
2010-03-29
63
问题
下列程序的输出结果是【 】。
#include <iostream>
using namespace std;
class base {
public:
int n;
base(iht x) {n=x;}
virtual void set(int m) {n=m;cout<<n<<’’;}
};
class deriveA: public base {
public:
deriveA(int x):base(x) {}
void set(int m){n+=m;cout<<n<<’’;}
}:
class deriveB:public base {
public:
deriveB(int x):base(x) { }
void set(int m) {n+=m;cout<<n<<’’;}
};
int main()
deriveA d1(1);
deriveB d2(3);
base *pbase;
pbase=&d 1;
pbase->set(1);
pbase=&d2;
pbase->set(2);
return 0;
选项
答案
5
解析
虚函数以及多态的概念,调用某一处理。
转载请注明原文地址:https://kaotiyun.com/show/eHjp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
以下选项中不属于C语言程序运算符的是
有以下程序#include<stdio.h>#include<string_h>voidfun(char*W,intm){chars,*p1,*p2;p1=w;p2=w+m-1;while(pl<p2){s=*p1;*p1=*p2;*p2=s;
在深度为7的满二叉树中,度为2的结点个数为
有以下程序#include<stdio.h>main(){FILE*f;f=fopen("filea.txt","w");fprintf("abc");fclose(f);}若文本文件filea.txt中原有内容为:hello,则运行以上程序
以下函数的功能是:通过键盘输入数据,为数组中的所有元素赋值。#include#defineN10voidfun(intx[N]){inti=0;while(i<N)scanf("%d",___);}在程序中下划线处应填入
计算机高级语言程序的运行方法有编译执行和解释执行两种,以下叙述中正确的是
若有定义“intx,y;”并已正确给变量赋值,则以下选项中与表达式“(x-y)?(x++):(y++)”中的条件表达式(x.y)等价的是
设有以下函数:voidfun(intn,char*s){……}则下面对函数指针的定义和赋值均正确的是
软件设计中模块划分应遵循的准则是()。
随机试题
小儿肺炎痰热闭肺证的首选方剂是()
鉴别右心衰竭与肝硬化的要点是
施工成本控制的实施步骤中,在预测之前需进行( )。
能够集中反映统治阶级的意志和利益,规定国家制度、社会制度的基本原则,具有最高法律效力的根本大法是()。
经济寿命是指设备从投入使用开始,到因继续使用经济上不合理而被更新所经历的时间段。它是由( )决定的。
下列关于负债的相关说法中,不正确的是()。
在各种市场要素中,价格是核心。()
新课程提倡教学过程中的师生互动,就是老师讲课时多提问、学生积极地举手回答。()
Themysterioustigerhasbeenasymbolofpowerandstrengthforcenturies.Itspowerisa【56】tohunters,【57】havetriedtokill
Students’pressuresometimescomesfromtheirparents.Mostparentsarewell【B1】_______,butsomeofthemaren’tveryhelpfulwi
最新回复
(
0
)