Home > Java > Javagetting Started > java what is encapsulation

java what is encapsulation

爱喝马黛茶的安东尼
Release: 2019-11-14 17:38:51
Original
5963 people have browsed it

java what is encapsulation

1. The concept of encapsulation:

Hiding some information of a class inside the class is not allowed External programs access directly, but operate and access hidden information through the methods provided by this class.

2. Benefits:

(1) Data can only be accessed through specified methods;

(2) Hide the instance details of the class, which is convenient Modification and implementation.

3. Encapsulation implementation steps:

(1) Modify the visibility of the attribute to (private)

(2) Create getter/ The setter method (used for reading and writing attributes) (data is obtained and set through these two methods, and the object reads and writes data by calling these two methods)

(3) In the getter Add attribute control statements to the /setter method (to judge the legality of attribute values)

php Chinese website, a large number of free Java introductory tutorials, welcome to learn online!

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

Related labels:
Statement of this Website
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
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template