prev next prev next
  Course navigation
  Lesson 5 Controlling access in Java
 
Objective
Control access to Java classes and class members.
    Access Modifiers Significance
You control the access to a class using access modifiers, which define different levels of access for class members. For example, you might want the member variables for a class to only be accessible to derived classes.
You must declare an access modifier before the type of a member variable, the return type of a method, or the definition of a class. Java supports four different access modifiers: public, protected, default, private. Some of these modifiers apply to classes, some to class members, and some to both:
   
public Classes, class members
protected Class members
default Classes, class members
private Class members
php, soa testing, oracle
surveillance, pmp, BACKHAUL
This Slideshow shows how the different access modifiers apply to a group of classes.
The frames demonstrate accessibility with respect to the Dog class:
Image

Control Access
  Course navigation