我想从基类继承Constructor。 我需要它来打印/制作新对象。
namespace Zoo
{
class Animal
{
public string Name { get; set; }
public int Age { get; set; }
public int Weigth { get; set; }
public Animal()
{
Name = "nieznane";
Age = 0;
Weigth = 0;
}
public Animal(string Name,int Age, int Weigth)
{
this.Name = Name;
this.Age = Age;
this.Weigth = Weigth;
}
public void Introduce()
{
Console.WriteLine(string.Format("{0} {1}y, {2}kg", Name, Age, Weigth));
}
}// class end
class Mammal : Animal
{
public string FurColour { get; set; }
public Mammal()
{
FurColour = "nieznane";
}
public Mammal(string furColour)
: base( Name,Age,Weigth) // there is the problem , this dont work
{
FurColour = furColour;
}
}
}
答案 0 :(得分:1)
您应提供Name
,Age
,Weigth
:
public Mammal(string Name, int Age, int Weigth, string furColour)
: base(Name, Age, Weigth)
{
FurColour = furColour;
}