Default keyword in Java 8
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.
Overview
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:
defaultString 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 adefaultvariable. Hence,defaultdoes not need to be explicitly written.
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved