首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
下列程序的执行结果为【 】。 #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
73
问题
下列程序的执行结果为【 】。
#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>main()(intstlm=10,n=1;while(n<3){sum=sum—n;n++;}printf("%d,%d
有以下程序#include<stdio.h>#include<string.h>structA{inta;charb[10];doublec;};structAf(structAt);main(){structAa={10
若有以下程序:#includemain(){inta=1,b:2;for(;a<8;a++){b+=a;a+=2;}printf("%d,%d\n",a,b);}则
若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
随机试题
在小儿年龄分期中,幼儿期是指
CA1092型汽车驻车制动鼓工作表面磨损起槽不得大于0.05mm。()
Mostofthepoemsin______singofthe"en-masse"andtheselfaswell.
下列有关软产道的变化特点,正确的是
根据《关于城镇医药卫生体制改革的指导意见》,把医院的门诊药房改为药品零售企业,独立核算,照章纳税,要解决的主要问题是
车辆停放方式按车身纵方向与通道的夹角关系有()
PowerBuilder所提供的对象不包括______。
A、Signhisnameforthefan.B、Fillinanapplicationform.C、Exchangegiftswithhisfriends.D、Getapurchaserefunded.D对话中男士
【B1】【B5】
AdetailedandthoroughresearchprojectundertakenbytheOpenUniversityrecentlyreportedthattheirevidenceappearstoshow
最新回复
(
0
)