Encapsulation in java

Pubblicato il: 22 aprile 2020
sul canale di: ShreeHub
86
4

Encapsulation is the process of wrapping the data (variables) and the code associated with those data (methods) within a single unit.

Encapsulation is used to hide the values or state of a structured data object inside a class, preventing direct access to them.
Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods.
To achieve encapsulation, the programmer declares the class variables as “private” and then provides what are called public “setter and getter” methods which make it possible to view and modify the variables

If a field is declared private, it cannot be accessed by anyone outside the class, thereby hiding the fields within the class.For this reason, encapsulation is also referred to as data hiding.

A class can have total control over what is stored in its fields.
The fields of a class can be made read-only or write-only.
The users of a class do not know how the class stores its data.
A class can change the data type of a field and users of the class do not need to change any of their code.
Encapsulation allows access to a level without revealing the complex details below that level.
The main benefit of encapsulation is the ability to modify implemented code without breaking the code of others who use our code.
Encapsulation gives maintainability, flexibility and extensibility to our code.


In questa pagina del sito puoi guardare il video online Encapsulation in java della durata di ore minuti seconda in buona qualità , che l'utente ha caricato ShreeHub 22 aprile 2020, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 86 volte e gli è piaciuto 4 spettatori. Buona visione!