animal.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace work102
{
public abstract class Animal
{
protected string name;
public Animal()
{
this.name = "Animal";
}
public abstract string ToSay();
}
public class Bird : Animal
{
public Bird()
{
this.name = "Bird";
}
public override string ToSay()
{
return this.name;
}
}
public class People : Animal
{
public People()
{
this.name = "People";
}
public override string ToSay()
{
return this.name;
}
}
}
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 work102
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//work102.Animal an = new Animal(); //抽象类不可实例化
//an.ToSay();
work102.Bird b1 = new Bird();
Response.Write(b1.ToSay());
Response.Write("<br>");
work102.People p1 = new People();
Response.Write(p1.ToSay());
Response.Write("<br>");
}
}
}