C# - 密封类Sealed

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 /*------------------------------------------------------------------------------------------------------------
 7  * 密封类:
 8  *      1. 使用关键字 : sealed 修饰类名
 9  *      2. 不能被继承
10 ------------------------------------------------------------------------------------------------------------*/
11 namespace 密封类
12 {
13     // 密封类: 基类
14     public sealed class SealedClass
15     {
16         //
17     }
18 
19     // 派生类 : 派生自密封类SealedClass
20     public class TestSealedClass : SealedClass
21     {
22         // 会出现编译错误,因为密封类不可以被继承
23     }
24 
25     class Program
26     {
27         static void Main(string[] args)
28         {
29         }
30     }
31 }

 

posted @ 2016-04-05 15:26  C/C++/Python/Java  阅读(357)  评论(0编辑  收藏  举报