public partial class test02 : System.Web.UI.Page
{
class People
{
public People()
{
//构造函数
}
public string Eating()
{
return "基类Eating方法被调用!";
}
public string Sleep()
{
return "基类Sleep方法被调用!";
}
}
class Student : People
{
public Student()
{
}
public string study()
{
return "派生类study方法被调用";
}
}
protected void Page_Load(object sender, EventArgs e)
{
People people1 = new People();
Label1.Text = people1.Eating();
Student student1 = new Student();
Label2.Text = student1.Eating();
Student student2 = new Student();
Label3.Text = student2.study();
}
}
{
class People
{
public People()
{
//构造函数
}
public string Eating()
{
return "基类Eating方法被调用!";
}
public string Sleep()
{
return "基类Sleep方法被调用!";
}
}
class Student : People
{
public Student()
{
}
public string study()
{
return "派生类study方法被调用";
}
}
protected void Page_Load(object sender, EventArgs e)
{
People people1 = new People();
Label1.Text = people1.Eating();
Student student1 = new Student();
Label2.Text = student1.Eating();
Student student2 = new Student();
Label3.Text = student2.study();
}
}
结果:
基类Eating方法被调用!
基类Eating方法被调用!
派生类study方法被调用
基类Eating方法被调用!
派生类study方法被调用
浙公网安备 33010602011771号