- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is a sealed class in C#?
Sealed class in C# with the sealed keyword cannot be inherited. In the same way, the sealed keyword can be added to the method.
When you use sealed modifiers in C# on a method, then the method loses its capabilities of overriding. The sealed method should be part of a derived class and the method must be an overridden method.
Let us see an example of sealed class in C# −
Example
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo { class Program { static void Main(string[] args) { Result ob = new Result(); string str = ob.Display(); Console.WriteLine(str); Console.ReadLine(); } } public sealed class Result { public string Display() { return "Passed"; } } }
To access the members of the sealed class, we need to create the object. The method created inside the sealed class cannot be inherited −
public sealed class Result { public string Display() { return "Passed"; } }
Advertisements
To Continue Learning Please Login
Login with Google