Junior — Middle
Is it possible to prevent classes from inheriting from a specific class in a programming language?
sobes.tech AI
Answer from AI
In Swift, you can prevent inheritance from a class by declaring it as final. Such a class cannot be used as a base for other classes.
Example:
final class MyClass {
// class code
}
// Attempting to inherit will cause a compile-time error
// class SubClass: MyClass {} // Error
In Objective-C, there is no direct equivalent of final, but you can use various patterns or warnings to restrict inheritance; however, this is not a built-in language feature.