首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
下列程序的执行结果为【 】。 #include <iostream. h> class Point { public: Point(double i, double j) { x=i;
下列程序的执行结果为【 】。 #include <iostream. h> class Point { public: Point(double i, double j) { x=i;
admin
2010-06-06
25
问题
下列程序的执行结果为【 】。
#include <iostream. h>
class Point
{
public:
Point(double i, double j) { x=i; y=j;}
double Area() const { return 0.0;}
private:
double x, y;
};
class Rectangle: public Point
{
public:
Rectangle(double i, double j, double k, double 1)
double Area() const {return w * h;}
private:
double w, h;
};
Rectangle: :Rectangle(double i, double j, double k. double 1): Point(i,j).
{
w=k, h=1
}
void fun(Point &s)
{
cout<<s. Area()<<end1;
}
void main( )
{
Rectangle rec(3.0, 5.2, 15.0. 25.0);
fun(rec)
}
选项
答案
0
解析
注意本题不同于基类的指针指向派生类对象。Fun函数的形参是Point基类的引用。在可以用基类对象的地方,均可以用派生类替代,完成基类的行为。反之,在使用派生类对象的地方却不能用基类对象代替,这是因为派生类中的某些行为在基类对象中是不存在的。本题调用的是Point类对象的面积函数,其值永远为0。
转载请注明原文地址:https://kaotiyun.com/show/8yjp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有以下程序:#include<stdio.h>main(){FILE*pf;char*s1="China",*s2="Beijing";pf=fopen("abc.dat","wb+"
有以下程序#include<stdio.h>#include<string.h>structA{inta;charb[10];doublec;};structAf(structAt);main(){structAa={10
有如下程序#include<stdio.h>intsum_mod(inta,intb){returna+b%2;}main(){inti;for(i=0;i<5;i++)
执行以下程序段后,w的值为()。intw=’A’,x=14,y=15;w=((x‖y)&&(w
若i、j已定义成int型,则以下程序段中内循环体的总执行次数是()。for(i=6;i>0;i--)for(j=0;j
计算机能直接执行的程序是()。
有以下程序:#include<stdio.h>#include<string.h>main(){chara[10]="abcd":printf("%d,%n",strlen(a),siz
随机试题
抢救休克型中毒性痢疾,哪项措施不得当
影响Χ线强度的因素中,不包括
某实验室用同一检验方法测定食品中的铅。小李的测定误差为2%,小王的测定误差为10%,经统计检验,检测结果不存在离群值。两人检测的误差相差那么大,是因为存在
对于不同的生态功能区实行分类管理政策,产业政策要引导优化开发区域转移(),提升产业结构层次。
甲公司为增值税一般纳税人,适用的增值税税率为17%,每月月初发放上月工资,2016年12月1日,“应付职工薪酬”科目贷方余额为33万元。该企业2016年12月发生职工薪酬业务如下:(1)5日,结算上月应付职工薪酬33万元。其中代扣代缴的职工个人所得税1.
关于中期财务报告的确认与计量,下列说法中正确的有()。
2016年8月28日,中国航空发动机集团公司成立大会在北京举行。下列关于航空发动机的说法错误的是()。
新民主主义理论的基本点有
如果一个过程不包含RETURN语句,或者RETURN语句中没有指定表达式,那么该过程:
Thiswillmakeschoolsmoredirectlyandeffectively______toparents,andmoreresponsivetotheircriticismsandwishes.
最新回复
(
0
)