Daffodils English School
Sanjaynagar, Bengaluru – 560 094.
Grade 10 (ICSE) Computer Applications
Unit : Encapsulation
-------------------------------------------------------------------------------------------------------------------
Scope of Syllabus
Access specifiers and its scope and visibility.
Access specifiers – private, protected and public. Visibility rules for private, protected and public access
specifiers. Scope of variables, class variables, instance variables, argument variables, local variables.
-------------------------------------------------------------------------------------------------------------------
Introduction
Access specifiers in Java are fundamental tools used to control the visibility and accessibility of classes, methods,
constructors, and variables within a program. They define who can access a particular member of a class and
from where, ensuring that the structure and security of the program are maintained.
By using access specifiers, we can:
1. Encapsulate Data: Protect sensitive information by restricting access.
2. Promote Modular Design: Allow controlled interaction between different parts of a program.
3. Enhance Security: Prevent unauthorized access to critical components.
Java provides four types of access specifiers:
1. Public: Accessible from anywhere in the program.
2. Private: Accessible only within the defining class.
3. Protected: Accessible within the same package and to subclasses in other packages.
4. Default (Package-Private): Accessible only within the same package, with no explicit keyword.
Access specifiers play a crucial role in implementing object-oriented programming principles like
encapsulation, inheritance, and abstraction, enabling programmers to write secure, organized, and reusable
code.
1. Public
• Keyword: public
• Scope & Visibility:
o Accessible from anywhere in the program, across different packages.
o Used for members that should be globally accessible.
• Use Case: APIs, methods, or classes that need universal accessibility.
2. Private
• Keyword: private
• Scope & Visibility:
o Accessible only within the same class.
o Cannot be accessed directly from outside the class.
o Ensures data encapsulation.
• Use Case: For sensitive data that should not be exposed.
3. Protected
• Keyword: protected
• Scope & Visibility:
o Accessible within the same package and by subclasses (even in different packages) through
inheritance.
o Used when you want to provide controlled visibility to subclasses.
• Use Case: To allow subclasses to inherit and use certain members.
4. Default
• Keyword: No keyword
• Scope & Visibility:
o Accessible only within the same package.
o Not accessible from classes in other packages.
o Ensures members are package-restricted.
• Use Case: For classes or members that should not be accessed outside the package.
Summary Table
Outside Package Outside Package
Access Modifier Within Class Within Package
(Subclass) (Non-Subclass)
public ✔ ✔ ✔ ✔
protected ✔ ✔ ✔ ✘
default ✔ ✔ ✘ ✘
private ✔ ✘ ✘ ✘
===========================