public partial class Default2 : System.Web.UI.Page { class A { public int Fun1(int num) { return num; } public int Fun3(int num) { return num + 2; } } class B : A { public int Fun1(int num) { return num + 1; } public int Fun2(A a, int num) { //return a.Fun3(num); //对于B中于A中同名的方法Fun1,只有在重写关系下,A中的Fun1才会被更改,覆盖 //调用a中的Fun1 return a.Fun1(num); } } protected void Page_Load(object sender, EventArgs e) { A a = new A(); B b = new B(); //B类派生于A类,认为实例b为A类 //但实例a不为B类 if (b is A) { Response.Write("Yes"); } Response.Write(b.Fun1(5)); //输出6 //调用实例b的方法Fun2传入b会调用其基类中的Fun1 Response.Write(b.Fun2(b,5)); //输出5 Response.Write(b.Fun2(a,5)); //输出5 } }