Declaring Methods  «Prev  Next»


Lesson 8Other modifiers
ObjectiveIntroduce and explain the other modifiers supported by Java.

Java - Non Access Modifiers

Abstract

The abstract modifier identifies abstract classes and methods. Abstract classes declare abstract methods and defer the implementation of these methods to their subclasses. When an abstract method is declared, its body is replaced by a semicolon.

Final

The final modifier is used with classes, field variables, local variables, methods, and method parameters. It indicates that an item may not be changed. A final class may not be subclassed. A final variable or parameter may not have its value changed (once it has been initialized). A final method may not be overridden.


Native

The native modifier identifies a native method. Native methods are written in languages other than Java and executed outside the Java virtual machine. The body of a native method is replaced by a semicolon when it is declared. Native methods may not be abstract.


Static

The static modifier identifies a variable or method that applies to a class as a whole rather than to specific instances of a class. Static variables are shared by all class instances. Static methods are invoked on the class in which they are declared, as well as on instances of a class. Static inner classes are covered in Module 3.

Synchronized

The synchronized modifier identifies synchronized methods and synchronized statements.

Transient

The transient modifier identifies a variable that may not be serialized. A transient variable may not be declared as final or static.

Volatile

The volatile modifier is used to indicate that a variable may be modified asynchronously in a multiprocessor environment.