Sobes.tech
Junior — Middle

Is it possible to make a class non-inheritable in a specific system or programming language?

sobes.tech AI

Answer from AI

In C#, you can prevent a class from being inherited by declaring it as sealed. Such a class cannot be inherited by other classes.

Example:

sealed class MyClass
{
    // class body
}

// Attempting to inherit will cause a compile-time error:
// class Derived : MyClass {} // Error

This is useful when you want to restrict the extensibility of a class and ensure its immutability in the inheritance hierarchy.