美文网首页
方法重写:Rules for method overriding

方法重写:Rules for method overriding

作者: BenjaminCool | 来源:发表于2018-12-28 09:35 被阅读1次

    https://www.geeksforgeeks.org/overriding-in-java/

    Overriding and Access-Modifiers :

    Final methods can not be overridden :

    Static methods can not be overridden(Method Overriding vs Method Hiding)

    Private methods can not be overridden

    The overriding method must have same return type (or subtype) :

    Overriding and Exception-Handling

    Rule#1 :

    如果超类重写方法没有抛出异常,子类重写方法只能抛出 unchecked exception,
    抛出 checked exception 将导致编译时错误。

    Rule#2 :

    If the super-class overridden method does throws an exception, subclass overriding method can only throw same, subclass exception.

    Overriding and synchronized/strictfp method

    对方法重写没有任何影响:
    synchronized / strictfp方法可能会覆盖非synchronized / strictfp方法,反之亦然。

    相关文章

      网友评论

          本文标题:方法重写:Rules for method overriding

          本文链接:https://www.haomeiwen.com/subject/bgajlqtx.html