animal.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace work103
{
public class Animal
{
protected string name;
public Animal(string name)
{
this.name = name;
}
public string GetName
{
get
{
return this.name;
}
}
public string ToSay()
{
return string.Format("{0}出声。", this.name);
}
}
//密封类不可再继承
public sealed class People : Animal
{
public People(string name) :base(name)
{
this.name = name;
}
public new string GetName
{
get
{
return this.name;
}
}
public new string ToSay()
{
return string.Format("{0}说话。",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 work103
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
work103.Animal an = new Animal("虾米");
Response.Write(an.GetName);
Response.Write("<br>");
Response.Write(an.ToSay());
Response.Write("<br>");
work103.People p1 = new People("大王");
Response.Write(p1.GetName);
Response.Write("<br>");
Response.Write(p1.ToSay());
Response.Write("<br>");
}
}
}