0% found this document useful (0 votes)
51 views13 pages

Data Hiding/Encapsulation in Java

The document discusses encapsulation and access modifiers in Java. It defines the four access modifiers as private, default, protected, and public and explains their scope - whether they can be accessed within the class, package, subclass, or outside the package. An example is also provided to demonstrate encapsulation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views13 pages

Data Hiding/Encapsulation in Java

The document discusses encapsulation and access modifiers in Java. It defines the four access modifiers as private, default, protected, and public and explains their scope - whether they can be accessed within the class, package, subclass, or outside the package. An example is also provided to demonstrate encapsulation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Data Hiding/Encapsulation in Java

1
Encapsulation
3
Access Modifiers in Java
 The access modifiers in Java specifies accessibility (scope) of a
data member, method, constructor or class.
 There are 4 java access modifiers:
1. private
2. default
3. protected
4. public
5
6
Access Modifier: Default

7
Access Modifier: Protected

8
Access Modifier: Public

9
Access Modifier: Private

10
11
Example To Demonstrate Encapsulation

OUTPUT: 12
Summary of Access Modifiers

Outside
Access Within Package by Outside
Within Class
Modifier Package subclass Package
Only

Private Yes No No No

Default Yes Yes No No

Protected Yes Yes Yes No

Public Yes Yes Yes Yes

You might also like