Title: Key Concept - Access Modifiers
Course: CPS 189: Java Certification - Review, Practice & Prepare (Development) > Section: (OLDstyle) Learning Modules

Access Modifiers

- Access modifiers control how a class, field, or method may be accessed outside the class.

Access Modifiers include:

- Public: The member is accessible from all other classes
- Private: The member is accessible only within the class

- A class must be declared public, abstract, or final.
- Generally, fields are declared private while methods are declared public.
- Declaring a field or method private carries out encapsulation.

Class member visibility:

Public:

- visible in the class
- visible in the package
- visible in subclasses of the class declared outside the package
- visible everywhere

Protected:

- visible in the class
- visible in the package
- visible in subclasses of the class declared outside the package
- not visible everywhere

No Modifier:

- visible in the class
- visible in the package
- not visible in subclasses of the class declared outside the package
- not visible everywhere

Private:

- visible in the class
- not visible in the package
- not visible in subclasses of the class declared outside the package
- not visible everywhere

For more information about Access Modifiers:

- Click this link to view Oracle's documentation: Controlling Access to Members of a Class.
- Level 1 Study Materials: Unit 5