I do not really understand the difference between the access modifier protected and default. If you do not specify anything?

  • one
    Described below, but what exactly is not clear? - user312477

2 answers 2

If you do not specify anything, then the default visibility will be - i.e. default.

Protected - "protected" is the visibility within the package boundaries and the visibility for successor classes. We can say that protected = default + inheritance.

    "Default Modifier".

    If a variable or method is not marked with any modifier, then it is considered that they are marked with a “default modifier”. Variables and methods with such a modifier are visible to all classes in the package in which they are declared, and only to them. This modifier is also called “package” or “package private”, hinting that access to variables and methods is open to the entire package that contains their class.

    Modifier "protected".

    This access level is slightly wider than the package. A variable, method, or class marked with the protected modifier can be accessed from its own package (as a package), but from all the classes inherited from the current one.