密封

密封类:密封类不可以被继承,抽象类不可以密封

    public sealed class Father
    {
        public  virtual void Eat()
        { 
        
        }
    }

密封方法:仅适用于重写的方法

    public class Son : Father,IFather
    {
        public sealed override void Eat()
        {
            //子类中进行重写抽象方法
            Console.WriteLine("虚方法重写");     
        }
    }

猜你喜欢

转载自www.cnblogs.com/Luck1996/p/11964138.html