Home  >  Article  >  Java  >  What is encapsulation in java

What is encapsulation in java

青灯夜游
青灯夜游Original
2019-05-16 18:08:356717browse

What is encapsulation in java

Encapsulation (Encapsulation) is an important principle of the object-oriented method, which is to combine the properties and operations (or services) of the object into an independent whole and hide the internal implementation of the object as much as possible detail.

In object-oriented programming methods, encapsulation refers to a method of packaging and hiding the implementation details of an abstract functional interface.

Encapsulation can be thought of as a protective barrier that prevents the code and data of the class from being randomly accessed by code defined by the external class.

To access the code and data of this class, you must pass strict interface control.

The main function of encapsulation is that we can modify our own implementation code without modifying the program fragments that call our code.

Proper encapsulation can make the program code easier to understand and maintain, and also enhance the security of the program code.

Advantages of encapsulation

1. Good encapsulation can reduce coupling.

2. The structure inside the class can be modified freely.

3. Member variables can be controlled more precisely.

4. Hide information and implement details.

Recommended related video tutorials: "JAVA Tutorial"

The above is the detailed content of What is encapsulation in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn