Accessibility scope of Java access modifiers

This question already has an answer here:

  • In Java, difference between package private, public, protected, and private 26 answers

  • For better understanding you need to see this

    Access Modifiers
    
                       Same Class      Same Package            Subclass     Other packages
    public               Y                Y                      Y                   Y
    protected            Y                Y                      Y                   N
    no access modifier   Y                Y                      N                   N
    private               Y               N                      N                   N
    


    Here the important difference is between Default and protected .
    Default: Never accessible outside the package
    Protected: Only accessible outside the package, if and only if the class is a subclass
    Please see this for further details.
    Edit: As your question's answer is also the same that You can access the protected member by make your class a sub class of the class , in which protected member is defined

    链接地址: http://www.djcxy.com/p/24060.html

    上一篇: LocalDate在LocalDate中拥有私人访问权限

    下一篇: Java访问修饰符的可访问性范围