CHAPTER 15

image

Access Levels

There are four access levels available in Java. These are public, protected, private and package-private. Package-private cannot be explicitly declared by using a keyword. Instead, it is the default access level for every member in Java.

public    int myPublic;   // unrestricted accessprotected int myProtected;// package or subclass access          int myPackage;  // package accessprivate   int myPrivate;  // class access

Private access

The most restrictive access level is private. Members with this level can only be used inside of the enclosing (containing) class.

package mypackage;public class MyApp{   public    int ...

Get Java Quick Syntax Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.