继承(三):封闭类不能派生子类

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

//封闭类不能派生子类
//原因:封闭类不能被作为基类使用
//好处:防止意外的派生的操作
//注意:抽象类不能作为封闭类使用(抽象类本质决定了他们必须被作为基类使用)
namespace InheritanceApp
{
    sealed class Point
    {
        public Point(int x, int y)
        {
            X = x;
            Y = y;
        }
        public int X;
        public int Y;
    }
    //语法错误:无法从密封类型Point派生   
    class MyPoint : Point
    { 
    }
    class Program
    {
        static void Main(string[] args)
        {
           
            Console.ReadKey();

        }
    }

   
}
posted @ 2011-03-09 19:51  焦涛  阅读(1972)  评论(0)    收藏  举报