Posts

Showing posts with the label C# | Sealed keyword

C# | Sealed keyword

C# sealed keyword applies restrictions on the class and method. If you create a sealed class, it cannot be derived. If you create a sealed method, it cannot be overridden. Note: Structs are implicitly sealed therefore they can't be inherited. C# Sealed class C# sealed class cannot be derived by any class. Let's see an example of sealed class in C#. using  System;   sealed   public   class  Animal{        public   void  eat() { Console.WriteLine( "eating..." ); }   }   public   class  Dog: Animal   {        public   void  bark() { Console.WriteLine( "barking..." ); }   }   public   class  TestSealed   {        public   static   void  Main()       {        ...