Encapsulation in java

Veröffentlicht am: 22 April 2020
auf dem Kanal: 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.


Auf dieser Seite können Sie das Online-Video Encapsulation in java mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer ShreeHub 22 April 2020 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 86 Mal angesehen und es wurde von 4 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!