Insurance Loans Mortgage Attorney Credit Lawyer Donate Degree Hosting Claim Conference Call Trading Software Recovery Transfer Gas/Electricity Classes Rehab Treatment Cord Blood
About Modifiers
Modifiers are keywords that you add to those definitions to change their meanings. The Java language has a wide variety of modifiers, including the following:
- Access Modifiers
- Non Access Modifiers
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
public class Car {
static int speed; // static modifer
public int gear; // public modifer
private int breakCar; // private modifer
final String modelNo = "Car-001"; // final modifer
protected int oilLevel = 100; // protected
public static boolean lightOn = false;
public static final int NUMBEROFWEEL = 4;
}
Access Control Modifiers:
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:
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.
No comments:
Post a Comment