The Java keywords that control the accessibility of a class and class members (variables, methods, and inner classes) are as follows:

  • public— Any part of a program can access this class or class member.

    • A public variable defies encapsulation

    • Public method provide servicess 

  • protected— Only methods in the same package or in subclasses can access protected class members. This keyword is not applied to classes.

  • private— Only methods in the same class can access a private member. This keyword is not applied to classes.

    • A private variable is visible within class, enforces encapsulation

    • A private method is created to support internal functions within a class.

  • (none)— If no access modifier is present, the class or member is visible only from classes in the same package. This is sometimes called "package" or default visibility.

The abstract modifier. An abstract method declares just the return type and parameter list of a method, not its body. Any class that contains an abstract method must be declared abstract, but note that a class can be declared abstract without containing any abstract method. Interfaces are always abstract, but the keyword is optional in the declaration. Variables can't be declared abstract.

The final modifier. A final method can't be overridden, and the value of a final variable cannot change after initialization. A local variable or method parameter must be declared final if an inner class declared inside a method will use it. A class can be declared final, in which case it cannot be extended.

The static modifier. Methods, variables, and nested classes can be declared static, in which case, they belong to the class as a whole, not any particular instance. Blocks of code outside a method can be declared static to initialize static variables.

The synchronized modifier. Methods and code blocks can be declared synchronized to prevent more than one thread from executing the code at the same time. When used with a code block, synchronized must be applied to an object.