MODIFIERS IN JAVA

Maha

MODIFIERS IN JAVA

Modifiers are keywords, that you can use to control the access, behavior, and scope of the classes, methods, variables, and other program of elements in java.

There are several types of modifiers in Java:

  •      Access modifiers
  •      Non-access modifiers 

Access Modifiers:

There are three types of access modifiers available in Java: 

Private - The private modifier restricts access within the same class.

Protected - The protected modifier allows to access within the same package and subclasses in different packages.

Non - Access Modifiers :

There are some types of non- access modifiers such as;

Final - The final modifier renders a method unoverridden (which cannot be overridden by subclasses), a class uninheritable (which cannot be extended), or a variable constant.

Abstract - The creation of abstract classes and methods makes use of the abstract modifier. An abstract class cannot be instantiated, and an abstract method must be overridden by the subclass because it is declared without an implementation.

Static - The class-level members (variables and methods) that can be accessed without creating an instance of the class are defined with the static modifier.

Synchronized - Controlling the simultaneous access of multiple threads to a shared resource with the synchronized modifier ensures that only one thread can access it at a time.

Volatile - Variables that are shared by multiple threads are given the volatile modifier to indicate that their values can be changed by multiple threads and to guarantee that the most recent value is always written to and read from the main memory.

Transient - Variables that shouldn't be used with Java's serialization API's default serialization mechanism are marked with the transient modifier.

Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send