Warning: Undefined array key 0 in /www/wwwroot/w/show/success.php on line 261

Warning: Trying to access array offset on value of type null in /www/wwwroot/w/show/success.php on line 261
_higrid.net-嗨网
当前位置:嗨网首页>书籍在线阅读

  
选择背景色: 黄橙 洋红 淡粉 水蓝 草绿 白色 选择字体: 宋体 黑体 微软雅黑 楷体 选择字体大小: 恢复默认

Warning: Undefined array key 0 in /www/wwwroot/w/show/success.php on line 266

Warning: Trying to access array offset on value of type null in /www/wwwroot/w/show/success.php on line 266

Warning: Undefined array key 0 in /www/wwwroot/w/show/success.php on line 266

Warning: Trying to access array offset on value of type null in /www/wwwroot/w/show/success.php on line 266

10.4.4 密封类

与抽象类相反的是,C#支持创建密封类,密封类是不能当做基类的类。其他的类不能从此类派生,从而保证了密封类的密封性和安全性。在C#中使用sealed关键字创建密封类,示例代码如下所示。

01  public sealed class Animal                           //创建密封类
02  {  
03          public Animal()                              //创建构造函数
04          {
05                  Console.WriteLine("Animal被构造");    //编写构造函数
06          }
07  }

当从Animal派生派生类时,编译器会提示出现错误。设计类的时候,通常情况下是不需要将类设置为密封类的,因为密封类会让类的扩展性非常差,这个类也无法再次扩展和派生。但是出于某种目的,当程序块只需要完成某些特定的功能或者在商业上为了保密,就可以使用密封类对类进行密封,以保证类的可靠性。


Warning: Undefined array key 0 in /www/wwwroot/w/show/success.php on line 276

Warning: Trying to access array offset on value of type null in /www/wwwroot/w/show/success.php on line 276

Warning: Undefined array key 0 in /www/wwwroot/w/show/success.php on line 276

Warning: Trying to access array offset on value of type null in /www/wwwroot/w/show/success.php on line 276