1. 程式人生 > >C# 抽象類、密封類

C# 抽象類、密封類

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication28
{
    class Program
    {
        static void Main(string[] args)
        {
            animal c = new cat();
            c.say();
        }
    }
    public abstract class animal
    {
        public abstract void say();
    }
    public class cat : animal
    {
        public override void say()//必須實現抽象類的抽象方法
        {
            Console.WriteLine("cat say");
        }
    }
    public sealed class A
    {
        public void fun()
        {
            Console.WriteLine("AAAAAAAAAAAAAa");
        }
    }
    /*無法從密封類中派生
    public class B : A  
    {

    }
    */
    public abstract class C
    {
        public virtual void fun() { }
    }
    public class D : C
    {
        public sealed override void fun()   //加上sealed後面的子類將不用實現虛方法
        {
            //base.fun();
        }
    }
    public class E : D
    {

    }
}