Hibernate Tutorial

(Brent) #1

Example: TUTORIALS POINT


Java Modifier Types


M


odifiers arekeywords that you add to those definitions to change their meanings. The Java language

has a wide variety of modifiers, including the following:

1. Java Access 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).

Default Access Modifier - No keyword:


Default access modifier means we do not explicitly declare an access modifier for a class, field, method, etc.

A variable or method declared without any access control modifier is available to any other class in the same
package. The fields in an interface are implicitly public static final and the methods in an interface are by default
public

Example:


Variables and methods can be declared without any modifiers, as in the following examples:

String version ="1.5.1";

boolean processOrder(){
return true;
}

CHAPTER


7

Free download pdf