using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#region Overview
//Using sealed in a class declaration prevents other classes from inheriting this class; using it in a method declaration The sealed modifier prevents extending classes from overriding this method.
//The sealed modifier is mainly used to prevent unintentional derivation, but it can also promote certain runtime optimizations. Specifically, since a sealed class will never have any derived classes, calls to virtual function members of instances of the sealed class can be converted to non-virtual calls for processing.
//密封类://密封类在声明中使用sealed 修饰符,这样就可以防止该类被其它类继承。如果试图将一个密封类作为其它类的基类,C#将提示出错。理所当然,密封类不能同时又是抽象类,因为抽象总是希望被继承的。//在哪些场合下使用密封类呢?实际上,密封类中不可能有派生类。如果密封类实例中存在虚成员函数,该成员函数可以转化为非虚的,函数修饰符virtual 不再生效。#endregionnamespace Sealed密封类 { class NOSealed { public static void OO() { Console.WriteLine("没有使用密封"); } } sealed class YESSealed { public static void OO() { Console.WriteLine("使用了密封"); } } class MyClass : NOSealed //YESSealed 那就错了 { public new void OO() { Console.WriteLine("没有继承密封"); } } //密封类不可以被继承,可以被调用 sealed class mysealed //声明为密封类 { public int x; public int y; } class Program { static void Main(string[] args) { NOSealed.OO(); MyClass M = new MyClass(); M.OO(); //调用密封类 YESSealed.OO(); mysealed m = new mysealed(); m.x = 100; m.y = 200; Console.WriteLine("x={0}, y = {1}", m.x, m.y); Console.ReadLine(); Console.ReadKey(); } } }

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Notepad++7.3.1
Easy-to-use and free code editor
