using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 抽象类
{
public abstract class BaseClass
{
public void BaseMethod()
{
Console.WriteLine("我是抽象类中的非抽象方法");
}
public abstract void DrivedMethod();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 抽象类
{
public class DrivedClass:BaseClass
{
public override void DrivedMethod()
{
Console.WriteLine("我是子类【派生类】中的重写方法");
//throw new NotImplementedException();
}
}
}
3.程序调用:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 抽象类
{
class Program
{
static void Main(string[] args)
{
//BaseClass baseClass = new DrivedClass();
//baseClass.BaseMethod();
//baseClass.DrivedMethod();
//Console.WriteLine();
//Console.ReadKey();
DrivedClass driveClass = new DrivedClass();
driveClass.BaseMethod();
driveClass.DrivedMethod();
Console.WriteLine();
Console.ReadKey();
}
}
}
上面注释的代码,和没有注释的代码,执行的效果是一样的。