Lesson: FIRST in Class Controlling Access to Members of a Class

Overview: 
Introduction to access control modifier keywords.
Objectives: 

Gain a basic understanding of access control modifiers.

Content: 

You have seen the access control modifier public used extensively in our Java examples. The access control modifier is applied to classes and class members (variables and methods) and determines what access code in other classes have to the class members.

Classes can have no access modifier before the class name and will default to package-private. This means the class is only visible to top level classes in the same package. You can also use public, which means the class is visible inside and outside of its package.

In robotics, using public for everything will work fine. Access modifiers become important when creating libraries that will be shared with other projects. In those cases, there may be internal members that should not be exposed to users of the library.

We will discuss access control in more detail in a later lesson.

 

Navigation: