Java Modifiers:
Like other languages it is possible to modify classes, methods etc by using modifiers. There are two categories of modifiers.
Ø Access Modifiers : default, public , protected, private
Java provides a number of access modifiers to set access levels for classes, variables, methods and constructors. The four access levels are:
· Visible to the package. the default. No modifiers are needed.
· Visible to the class only (private).
· Visible to the world (public).
· Visible to the package and all subclasses (protected).
Ø Non-access Modifiers : final, abstract, strictfp
Java provides a number of non-access modifiers to achieve many other functionality.
· The static modifier for creating class methods and variables
· The final modifier for finalizing the implementations of classes, methods, and variables.
· The abstract modifier for creating abstract classes and methods.
· The synchronized and volatile modifiers, which are used for threads.
To use a modifier, you include its keyword in the definition of a class, method, or variable. The modifier precedes the rest of the statement, as in the following examples (Italic ones):
public class className {
// ...
}
private boolean myFlag;
static final double weeks = 9.5;
protected static final int BOXWIDTH = 42;
public static void main(String[] arguments)
{
// body of method
}
Like other languages it is possible to modify classes, methods etc by using modifiers. There are two categories of modifiers.
Ø Access Modifiers : default, public , protected, private
Java provides a number of access modifiers to set access levels for classes, variables, methods and constructors. The four access levels are:
· Visible to the package. the default. No modifiers are needed.
· Visible to the class only (private).
· Visible to the world (public).
· Visible to the package and all subclasses (protected).
Ø Non-access Modifiers : final, abstract, strictfp
Java provides a number of non-access modifiers to achieve many other functionality.
· The static modifier for creating class methods and variables
· The final modifier for finalizing the implementations of classes, methods, and variables.
· The abstract modifier for creating abstract classes and methods.
· The synchronized and volatile modifiers, which are used for threads.
To use a modifier, you include its keyword in the definition of a class, method, or variable. The modifier precedes the rest of the statement, as in the following examples (Italic ones):
public class className {
// ...
}
private boolean myFlag;
static final double weeks = 9.5;
protected static final int BOXWIDTH = 42;
public static void main(String[] arguments)
{
// body of method
}