3 Visibility Modifiers

 

After reading lesson 3, you will be able to:

  • Organize your application using packages
  • Understand the options for visibility modifiers
  • Choose the correct modifier for your code

The visibility modifiers determine the access level of the instance data, method, class, etc. In this lesson I will explain the concept of packages in Java, which is necessary to understand how visibility modifiers affect your application and review the various types that can be used.

One reason for using these modifiers is to restrict access.   Think about a banking application.  One of the classes would probably be for a bank account.  The bank account class might have a customer’s name, home address, birth date, etc.  If access to these fields is marked as public, then there is no way to validate that changes are made correctly.  For example, the birth year could be set to an invalid year such as 2100. 

3.1   Packages

 
 
 

3.2   Visibility Modifiers Explained

 
 

3.3   Visibility Modifiers in Action

 
 

3.4   Summary

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest