Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
25 views

Java 1

Java provides four access modifiers: public which is accessible to everyone, private which is only accessible within the class, protected which is accessible to the containing package and subclasses, and default which is accessible within the package. Encapsulation in Java is mostly useful to hide data and decide who can access it. The advantages of encapsulation include making code more flexible and easy to change, preventing access to private fields, allowing modification without breaking other code, keeping data and code safe from external inheritance, and improving maintainability.

Uploaded by

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

Java 1

Java provides four access modifiers: public which is accessible to everyone, private which is only accessible within the class, protected which is accessible to the containing package and subclasses, and default which is accessible within the package. Encapsulation in Java is mostly useful to hide data and decide who can access it. The advantages of encapsulation include making code more flexible and easy to change, preventing access to private fields, allowing modification without breaking other code, keeping data and code safe from external inheritance, and improving maintainability.

Uploaded by

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

Java provides four access modifiers.

 public: Accessible to everyone.
 private: Accessible only within the class.
 protected: Accessible to the containing package and the subclasses.
 default: Accessible within the package.

Why is Encapsulation used in Java?

Encapsulation in Java is mostly useful to hide the data. Or in other words, to decide about the access
given to data as to who can access it, and who cannot.

What are the advantages of Encapsulation?

1. The encapsulated code is more flexible and easy to change with new requirements.
2. It prevents the other classes to access the private fields.
3. Encapsulation allows modifying implemented the code without breaking others code who have
implemented the code.
4. It keeps the data and codes safe from external inheritance. Thus, Encapsulation helps to achieve
security.
5. It improves the maintainability of the application.

You might also like