|ZZ| c++ 5.17 覆盖...
May 18, 2007 17:44
..今天刚做的...谢谢fcc老师的帮忙....
//5.17
//先设计一个长方形类.再通过继承长方形类设计一个正方形类,
//正方形类中通过覆盖父类的成员函数得到一些新的功能..
#include<iostream.h>
class Rectangle //长方形类.
{
public:
int x,y;
int area()
{
return x*y;
}
};
class square:public Rectangle //派生类...正方形类..
{
public:
int area() //覆盖长方形类中的 area.
{
return x*x;
}
square(int a) //构造函数.
{
x=a;
}
};
void main()
{
square f(4);
cout<<f.area()<<endl;
}
//先设计一个长方形类.再通过继承长方形类设计一个正方形类,
//正方形类中通过覆盖父类的成员函数得到一些新的功能..
#include<iostream.h>
class Rectangle //长方形类.
{
public:
int x,y;
int area()
{
return x*y;
}
};
class square:public Rectangle //派生类...正方形类..
{
public:
int area() //覆盖长方形类中的 area.
{
return x*x;
}
square(int a) //构造函数.
{
x=a;
}
};
void main()
{
square f(4);
cout<<f.area()<<endl;
}
------------------------------------07.05.18
|ZZ|胡思乱想...
|ZZ|星期六了...