zoukankan      html  css  js  c++  java
  • 诡秘的protected权限

    http://837062099.iteye.com/blog/1609340

    protected修改的属性和方法:

    相同:在同一个包中访问的时候和public、default修饰是一样的

    不同:在包外访问的时候要遵循一个原则

    But a subclass in another package can access the protected members in the super-class via only the references of subclass or its subclasses. A subclass in the same package doesn’t have this restriction. This ensures that classes from other packages are accessing only the members that are part of their inheritance hierarchy.

    1、在包外要访问protected修饰的member,那么这个包外要试图去访问protected修饰的member的类一定要是member所在类的子类或者子类的子类...

    2、只有通过这个包外类的引用或者其子孙类的引用才能访问到那个protected修饰的member

    这个引用包括this.method()

  • 相关阅读:
    322. Coin Change
    368.[LeetCode] Largest Divisible Subset
    c++
    python 循环
    2018今日头条
    c++中set的用法
    [LeetCode]48. Rotate Image 旋转图片
    [LeetCode]47. Permutations II
    [LeetCode]46. Permutations
    sys与os模块(转载)
  • 原文地址:https://www.cnblogs.com/jingyunyb/p/3806823.html
Copyright © 2011-2022 走看看