Instructional Material: Controlling access to members of a class

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.


Material Type: 
Education Level: 
Middle School
High School
Focus Subject: 
Computing / Computer Science
Robotics Software
HW Platform: 
SW Platform: 
Interactivity Style: