From the course: Advanced C#: Object-Oriented Programming
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Sealed classes - C# Tutorial
From the course: Advanced C#: Object-Oriented Programming
Sealed classes
- [Instructor] In C#, we can create classes that cannot be inherited from by using the sealed modifier. In this way, this is the direct opposite of the abstract modifier, which defines a class that must be inherited from, and can't be individually instantiated. By sealing a class, you can ensure that the functionality of the class can't be modified by other developers in unintended ways. And in fact, one of the most basic classes in the .NET framework is sealed, and that's the string class. So if you look at the string class definition, you can see that sure enough, it's a sealed class. All right, so let's take a look at how this works back in the main program. Let's open up our program code and our example code. And let's take a look at the first example. So I have two classes, I have class A and class B, and you can see that B inherits from class A. In my main program, the code creates an instance of Class B. So if I run…