.
Java Tutorial: Java Modifiers
Java Modifiers
- The java also has the feature like other language is we can modify the methods, classes using modifiers.
- There are two types of modifiers are available. It is used to restrict the access of data member and method in another class.
- 2 forms of access specifiers available .
The Access Controller – restrict the right to use level
Non – Access Controller – do not restrict but provides other functionality
The 4 types of access controller available.
- Default
- Private
- protected and
- Public
Default Controller (specifier):
- The default modifiers mean we need not to specify any modifiers.
- It is supported only limited package only. That is if we declare classNamewith default modifiers with imitated package.
- We can access only that package inside classNameother package not supported.
Private Modifiers:
- It restricts the access with in the classNameonly. So the private data members and methods accessed with in class.
- We cannot declare the classNameas private because if it have private constructor we may be not capable of creating an object from the classNameoutside
Public Modifiers:
- The public modifier properties are accessed anywhere from a program.
- There is no any restriction.
Protected Modifier:
- The protected modifier of data members and methods are imported within classNameof the similar package and sub classNamealso.
- It same like that default modifier but it is visible in sub classNamealso.
Example
.