主程序类
public class aa
{
Test1 test1;
public aa()
{
var className = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace+"."+nameof(Test3);
Type type = Type.GetType(className);
test1 = Activator.CreateInstance(type) as Test1;
test1.dd();
}
}
public abstract class Test1
{
public Test1()
{
}
public void TestMethod1(string s1)
{
Console.WriteLine(1);
}
protected abstract void TestMethod2(string s2);
public virtual void dd()
{
TestMethod2("1");
}
}
public class Test2 : Test1
{
protected override void TestMethod2(string s2)
{
Console.WriteLine(2);
}
}
public class Test3 : Test1
{
protected override void TestMethod2(string s2)
{
Console.WriteLine(3);
}
}