Visibility controlling access to members of a class

suggest change

Syntax

Remarks

From the Java tutorial:

Access level modifiers determine whether other classes can use a particular field or invoke a particular method. There are two levels of access control:

A class may be declared with the modifier public, in which case that class is visible to all classes everywhere. If a class has no modifier (the default, also known as package-private), it is visible only within its own package.

At the member level, you can also use the public modifier or no modifier (package-private) just as with top-level classes, and with the same meaning. For members, there are two additional access modifiers: private and protected. The private modifier specifies that the member can only be accessed in its own class. The protected modifier specifies that the member can only be accessed within its own package (as with package-private) and, in addition, by a subclass of its class in another package.

The following table shows the access to members permitted by each modifier.

Access Levels:

Modifier | Class | Package | Subclass | World | —— | —— | —— | —— | —— |public | Y | Y | Y | Y |protected | Y | Y | Y | N |no modifier | Y | Y | N | N |private | Y | N | N | N |

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Visibility controlling access to members of a class:
* Visibility controlling access to members of a class

Table Of Contents
8 Arrays
10 Maps
11 Strings
19 Visibility controlling access to members of a class
25 JAXB
29 Enums
32 Audio
41 Scanner
63 Logging
75 Lists
78 Sets
89 JAX-WS
96 XJC
98 Process
106 Modules
114 Applets
122 JNDI
139 JavaBean
141 Literals
144 Packages
150 JMX
153 JShell
159 Sockets
167 Enum Map
175 Hashtable
177 SortedMap