MODIFIERS

Modifiers:

There are seven modifiers available in Java ,they are

  1. ​Static
  2. Final
  3. abstract
  4. Native
  5. Transient
  6. Synchronized
  7. Votile.
  • ​Static:A static variable is a class variable and it does not belong to any objects.Usually static variable is used as a counter,every time when an object is created,the counter is incremented in the constructor .The value of counter indicates the number of objects created.to access static variable,static method is required because non-static method annot access static variable.Also static method is invoked using class name but not by any object.
  • Final:the final modifier can be used on class,method or variable definition.The final variable values cannot be changed after initialization;final method cannot be overriden and final class cannot be inherited.in a final class,all methods and data are final.
  • Abstract:The abstract modifier is the opposite form of final modifier.The abstract classes and methods are incomplete,so an abstract class must be inherited;an abstract method must be overriden in subclasses.
  • Native:A native modifier can be used for methods.It tels the compiler that the method has been defined in other language are used without rewriting the code in Java.
  • Transient: transient modifier is used on certain instance variables so that when objects are written in permanent files these variables values are not stored instead null values or zero is stored.Transient variables cannot be final or static.
  • Synchronized:The synochronized modifier is used in multithreaded programs.Synchronization is necessary to avoid race condition.
  • Volatile:The volatile modifier is used for variables that can be simultaneously modified by many threads.The compiler treats these data members in a special manner when they are updated.

The access specifier and modifier can be used in any order.

e.g.,

public static int x=0;

static public int x=0;

Here,both the declarrations are correct.compiler will not raise any error.

Posted on by