animal.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace work104
{
public abstract class Animal
{
public abstract string Sound();
public string EatFood()
{
return "";
}
}
public class Dog : Animal
{
public override string Sound()
{
return "汪汪";
}
public new string EatFood()
{
return "狗吃屎";
}
}
public class Bird : Animal
{
public override string Sound()
{
return "咕咕";
}
public new string EatFood()
{
return "鸟吃虫";
}
}
public class Cat : Animal
{
public override string Sound()
{
return "喵喵";
}
public new string EatFood()
{
return "猫吃鱼";
}
}
}
webform1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace work104
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
work104.Bird b1 = new Bird();
Response.Write(b1.Sound());
Response.Write(b1.EatFood());
Response.Write("<br>");
work104.Dog d1 = new Dog();
Response.Write(d1.Sound());
Response.Write(d1.EatFood());
Response.Write("<br>");
work104.Cat c1 = new Cat();
Response.Write(c1.Sound());
Response.Write(c1.EatFood());
Response.Write("<br>");
}
}
}