0% found this document useful (0 votes)
45 views9 pages

Packages and Access Specifiers

This document discusses packages, access specifiers, and their scope in Java. It defines a package as a group of classes and interfaces that can contain subpackages. Access specifiers like public, private, protected, and default control the visibility of classes and members. Public allows global access, private limits access to the class, protected allows access within the class and inheriting subclasses, and default allows access within the same package. The document provides tables detailing the scope and elements that each access specifier can be applied to.

Uploaded by

thuyhang_62
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views9 pages

Packages and Access Specifiers

This document discusses packages, access specifiers, and their scope in Java. It defines a package as a group of classes and interfaces that can contain subpackages. Access specifiers like public, private, protected, and default control the visibility of classes and members. Public allows global access, private limits access to the class, protected allows access within the class and inheriting subclasses, and default allows access within the same package. The document provides tables detailing the scope and elements that each access specifier can be applied to.

Uploaded by

thuyhang_62
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 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