0% found this document useful (0 votes)
232 views

8.1 Encapsulation-in-Java PDF

Encapsulation in Java involves wrapping code and data together into a single unit. A class can be fully encapsulated by making all data members private and using getter and setter methods to access the data. Encapsulation provides advantages like making a class read-only or write-only by only including getter or setter methods, giving control over the data, and achieving data hiding by preventing direct access to private data members from other classes.

Uploaded by

Pope Smith
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
232 views

8.1 Encapsulation-in-Java PDF

Encapsulation in Java involves wrapping code and data together into a single unit. A class can be fully encapsulated by making all data members private and using getter and setter methods to access the data. Encapsulation provides advantages like making a class read-only or write-only by only including getter or setter methods, giving control over the data, and achieving data hiding by preventing direct access to private data members from other classes.

Uploaded by

Pope Smith
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

JAVA

Encapsulation in Java
JAVA: Encapsulation in Java

➤ Encapsulation in Java : Encapsulation in Java is a process of


wrapping code and data together into a single unit.
➤ User can create a fully encapsulated class in Java by making all
the data members of the class private. And use setter and
getter methods to set and get the data in it.

JAVA: Encapsulation in Java

➤ Advantage of Encapsulation in Java


➤ By providing only a setter or getter method, you can make the
class read-only or write-only.
➤ It provides you the control over the data.
➤ It is a way to achieve data hiding in Java because other class
will not be able to access the data through the private data
members.
Will see you in Next Lecture…

See you in next lecture …

You might also like