Junior
Is the open class final or non-final?
sobes.tech AI
Answer from AI
Non-final. The keyword open explicitly indicates that you can inherit from this class and override its members.
open class BaseClass {
open func someMethod() {
// Default implementation
}
}
class DerivedClass: BaseClass {
override open func someMethod() {
// Overridden implementation
}
}
Let's compare with other access modifiers:
| Modifier | Inheritance | Overriding members |
|---|---|---|
private |
No (within file/scope) | No |
fileprivate |
No (within file) | No |
internal |
Yes (within module) | Yes (within module) |
public |
Yes (within module) | Yes (within module) |
open |
Yes (in any module) | Yes (in any module) |
final |
No | No |
A class or member marked final cannot be overridden or inherited, making it final. open does the opposite.