在父类中增加一个无参数的构造函数可以实现
class animal
{
public int eyes;
pubilc int legs;
protected float height;
public animal(){;} //在父类添加一个无参数的构造函数
public animal(int e,int l,float h)
{
eyes=e;
legs=l;
height=h;
}
}
class cow:animal
{
int num;
public animal(int e,int l,float h,int n):base(e,l,h)
{
eyes=e;
legs=l;
height=h;
num=n;
}
} |