c#程序定义一个animal接口,具有color,weight属性和sound,eat等方法,然 10
c#程序定义一个animal接口,具有color,weight属性和sound,eat等方法,然后创建继承该接口的dog,cat,cow类...
c#程序定义一个animal接口,具有color,weight属性和sound,eat等方法,然后创建继承该接口的dog,cat,cow类
展开
1个回答
展开全部
interface Animal
{
string Color
{
get;
set;
}
int Weight
{
get;
set;
}
void Sound();
void Eat();
}
class Dog : Animal
{
public string Color
{
get;
set;
}
public int Weight
{
get;
set;
}
public void Sound()
{
Console.WriteLine("Bow-wow!");
}
public void Eat()
{
Console.WriteLine("Dog ate.");
}
}
class Cat : Animal
{
public string Color
{
get;
set;
}
public int Weight
{
get;
set;
}
public void Sound()
{
Console.WriteLine("Mew...");
}
public void Eat()
{
Console.WriteLine("Cat ate.");
}
}
class Cow : Animal
{
public string Color
{
get;
set;
}
public int Weight
{
get;
set;
}
public void Sound()
{
Console.WriteLine("Moo...");
}
public void Eat()
{
Console.WriteLine("Cow ate.");
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询