Back
In Java, are there clear rules on when to use each of access modifiers, namely the default (package private), public, protected and private, while making class and interface and dealing with inheritance?
│ Class │ Package │ Subclass │ Subclass │ World │ │ │(same pkg)│(diff pkg)│ ────────────┼───────┼─────────┼──────────┼──────────┼──────── public │ + │ + │ + │ + │ + ────────────┼───────┼─────────┼──────────┼──────────┼──────── protected │ + │ + │ + │ + │ ────────────┼───────┼─────────┼──────────┼──────────┼──────── no modifier │ + │ + │ + │ │ ────────────┼───────┼─────────┼──────────┼──────────┼──────── private │ + │ │ │ │ + : accessible blank : not accessible
Here’s the official tutorial which you can use.
30.9k questions
32.9k answers
500 comments
665 users