Other answers already provide enough understanding about the final keyword. I want to explain with some example.
Let's look at the example below without a finalkeyword.
class A {
public var name: String
var breed: String
init(name: String, breed: String) {
self.name = name
self.breed = breed
}
}
class B:A{
override init(name: String, breed: String) {
super.init(name: name, breed: breed)
}
}
In the above code, this allows you to overwrite the variable of this superclass. A class with the last keyword does not allow. See below for an example.
final class A {
public var name: String
var breed: String
init(name: String, breed: String) {
self.name = name
self.breed = breed
}
}
class B:A{
**
override init(name: String, breed: String) {
super.init(name: name, breed: breed)
}
}
The code above will inherit errors from the final class A of class B
source
share