第八章-抽象类-抽象类和抽象方法示例

62 阅读1分钟

1.抽象类就是设计来给其他类继承的 2.抽象方法只能定义在抽象类中,抽象方法和普通方法都可以存在于抽象类中 3.抽象成员可以是:方法、属性、事件以及索引

namespace 抽象方法
{
    internal class Program
    {
        abstract class father
        {
            public void print()
            {
                Console.WriteLine("Just a normal method");
            }//普通方法
            abstract public void abPrint();//抽象方法
        }
        class son : father
        {
            public override void abPrint()
            {
                Console.WriteLine("I belong to abstract method");
            }
        }
            static void Main(string[] args)
        {
            new son().print();//继承的普通方法的调用
            new son().abPrint();//对覆写抽象方法的调用
            Console.ReadLine();
        }
    }
}