JAVA Access Modifiers

JAVA Access Modifiers is used to set access levels for classes, variables, methods and constructors.

Access Control Modifiers

There are four Access Modifiers as below.

  • default - Accessiable to the package. No modifiers are needed.
  • private - Accessiable to the class only
  • public - Accessiable to the all class  and its all subclasses within in same package.
  • protected - Accessiable to the package and all subclasses

Non-Access Modifiers

There are below Non-Access Modifiers  are avalilable.

  • static - It is used for class methods and variables
  • final - It is used for finalizing implementations of classes, methods, and variables
  • abstract - It is used for creating abstract classes and methods.
  • synchronized - It is used for threads.

Example :

public class Shop{
// public access specifier for class

static final double cost = 4.3;
protected static final int quantity = 132;
private boolean isSold;

public static void main(String[] arguments) {
// main method

}

}

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

62618