How do you prevent a class from being inherited?

In C#, we can use the sealed keyword to prevent a class from being inherited.

In C# (which is commonly used in .NET development), you can prevent a class from being inherited by using the sealed keyword. When you mark a class as sealed, it means that it cannot be used as a base class for other classes. Here’s how you do it:

csharp
sealed class MyClass
{
// Class members and methods
}

By marking a class as sealed, you’re essentially telling the compiler that this class is the final implementation and cannot be extended further through inheritance. This is useful when you want to ensure that certain behaviors or implementations are not altered or extended by other developers.