using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication4
{
public abstract class Test1
{
public void TestMethod1(string s1)
{
HttpContext.Current.Response.Write(s1);
}
protected abstract void TestMethod2(string s2);
}
public class Test2 : Test1
{
protected override void TestMethod2(string s2)
{
HttpContext.Current.Response.Write(s2);
}
}
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Test2 t2 = new Test2();
t2.TestMethod1("aa");
}
}
}
1、抽象類可以包含抽象方法和實例方法;抽象類可以沒有抽象方法,但有抽象方法的類一定是抽象類。
2、抽象方法聲明時沒有實現體,類似於接口中聲明的方法。
3、抽象方法必須在派生類中通過override覆寫來實現,這點也類似於接口,但不同的是實現接口的方法不用override。