What is the difference between final Class and Class?

前端 未结 7 2162
名媛妹妹
名媛妹妹 2020-12-25 09:40

What is the difference between final Class and Class?

final class A {

}

class B {    

}
相关标签:
7条回答
  • 2020-12-25 10:32

    Final is class modifier which prevents it from being inherited or being overridden. From apple documentation

    You can prevent a method, property, or subscript from being overridden by marking it as final. Do this by writing the final modifier before the method, property, or subscript’s introducer keyword (such as final var, final func, final class func, and final subscript).

    Any attempt to override a final method, property, or subscript in a subclass is reported as a compile-time error. Methods, properties, or subscripts that you add to a class in an extension can also be marked as final within the extension’s definition.

    You can mark an entire class as final by writing the final modifier before the class keyword in its class definition (final class). Any attempt to subclass a final class is reported as a compile-time error.

    0 讨论(0)
提交回复
热议问题