请按照下列要求,编写一个C#控制台应用程序.
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/23 15:17:43
请按照下列要求,编写一个C#控制台应用程序.
请按照下列要求,编写一个C#控制台应用程序.
请按照下列要求,编写一个C#控制台应用程序.
class Instrument
{
protected string _name { get; set; }
protected string _action { get; set; }
public virtual string Play()
{
return string.Format("{0}是{1}的", _name, _action);
}
}
class Piano : Instrument
{
public Piano()
{
_name = "钢琴";
_action = "弹";
}
}
class Violin : Instrument
{
public Violin()
{
_name = "小提琴";
_action = "拉";
}
}
class Horn : Instrument
{
public override string Play()
{
return "喇叭是吹的";
}
}static void Main(string[] args)
{
Instrument a = new Piano();
Instrument b = new Violin();
Instrument c = new Horn();
Console.WriteLine(a.Play());
Console.WriteLine(b.Play());
Console.WriteLine(c.Play());
Console.WriteLine("按回车退出...");
Console.Read();
}