Access Modifier | Types and Use of Access Modifier JAVA - Java2021 : Online Tutorials Hub

Java2021 : Online Tutorials Hub

JAVA | Advance Java | MySQL | Data Structure | Git | HTML | CSS | JS

Latest

Post Top Ad

Monday, May 11, 2020

Access Modifier | Types and Use of Access Modifier JAVA

Access Modifiers in Java

There are two types of modifiers in java

1.Access modifiers

2.Non-access modifiers.

The access modifiers in java specifies accessibility (scope) of a data member, method, constructor or class.

There are 4 types of java access modifiers:

  1. Default : If you don't use any modifier, it is treated as default bydefault. The default modifier is accessible only within package.
  2. Public : The public access modifier is accessible everywhere (Outside Package and Class).
  3. Private : The private access modifier is accessible only within class.
  4. Protected : The protected access modifier is accessible within package and outside the package but through inheritance only.the protected access modifier can be applied on the data member, method and constructor. It can't be applied on the class.

There are many non-access modifiers such as static, abstract, synchronized, native, volatile, transient etc.

Click for example of access modifier :

No comments:

Pages