There are many keywords in Java. One of them is the word default
. The word default
is an access-modifier. If a user does not assign any access-modifier to a class or its variables, Java, by default, assigns them the default
access-modifier.
The following table compares the accessibility of different access-modified variables:
Modifier | Class | Package | Sub-class | Global |
---|---|---|---|---|
Public |
Yes | Yes | Yes | Yes |
Private |
Yes | No | No | No |
Default |
Yes | Yes | No | No |
Protected |
Yes | Yes | Yes | No |
Note:
default
String s1 and String s1 is the same thing. As discussed earlier, when no access-modifier is mentioned, Java 8, by default, assumes the variable to be adefault
variable. Hence,default
does not need to be explicitly written.
Free Resources