问题 填空题

下列程序的执行结果为 【13】
#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。

单项选择题 A1/A2型题
单项选择题