zoukankan      html  css  js  c++  java
  • swift语言点评十四-继承

    Overriding

    A subclass can provide its own custom implementation of an instance method, type method, instance property, type property, or subscript that it would otherwise inherit from a superclass. This is known as overriding.

    Overriding by accident can cause unexpected behavior, and any overrides without the override keyword are diagnosed as an error when your code is compiled.

    The override keyword also prompts the Swift compiler to check that your overriding class’s superclass (or one of its parents) has a declaration that matches the one you provided for the override. This check ensures that your overriding definition is correct.

     

    Preventing Overrides

    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 varfinal funcfinal 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.

  • 相关阅读:
    BZOJ 4025: 二分图
    20180803 题解 Winniechen's Tesst
    前尘浮华一场梦 NOI2018 游记
    UOJ#311. 【UNR #2】积劳成疾
    欢迎到我的新Blog!
    弹飞大爷 BZOJ4764 LCT维护内向基环树森林
    [SCOI2007]修车 BZOJ1070
    KD-Tree
    CDQ分治
    深入解析DC/OS 1.8 – 高可靠的微服务及大数据管理平台
  • 原文地址:https://www.cnblogs.com/feng9exe/p/8717226.html
Copyright © 2011-2022 走看看