You are on page 1of 9

CHAPTER 4

PACKAGES AND
ACCESS SPECIFIERS
Objectives
 Explain and create package
 Identify the access specifier
 Define list field and method modifier

2/
Packages
 Package: group of classes and interfaces
 Contents more sub packages or zero
 Fully qualified name:

packagename.subpackagename.class
Ex: hospital.doctor
 Directory: hospital\doctor
 Syntax creating: package <packagename>

Ex: package hospital


 Syntax using: import packagename.class;
Ex: import hospital;

3/
Access specifiers
 Access specifier = Access modifier: controls
the access of class and class member.
 public: allows the class to be accessible
everywhere
 private: accessible only within its own class
 protected: accessible only within its own class,
package and inheriting classes.
 default: no specific keyword, accessed by any
other class in the same package

4/
Scope SubClass1
extends Class1

5/
Scope SubClass1
extends Class1

6/
Scope
Access Elements visible in
specifier Outside the package Package Subclass Class

public    
private    
protected    
default    
The scope of access specifiers

7/
Association
Access Can be applied to
specifier Data Field Method Constructor Class Interface

public     
private     
protected     
default     
Relationship between access specifiers and elements

8/
Q&A
9/

You might also like