search
HomeJavaJavagetting StartedHow to achieve encapsulation?

How to achieve encapsulation?

Jun 30, 2020 pm 05:17 PM
encapsulation

How to achieve encapsulation?

Encapsulation process:

(Recommended learning: java introductory program)

First, the variables will be privatized through private. Restrict access to class attributes

How to achieve encapsulation?

Then set the external access interface for each attribute through the set and get methods. Externally, if you need to change the attributes of the class, you need to use these public methods.

How to achieve encapsulation?

Then you need to create an instance of the encapsulated class, such as creating a Test class, making the variables private and the methods public. The set and get methods can be automatically generated

How to achieve encapsulation?

(Video tutorial recommendation: java video tutorial)

Continue to create a Test2 class, create an object of the Test class, and set the properties of the encapsulated class through the object , and then obtain these properties through the get method

How to achieve encapsulation?

Finally run the project, and you can see on the console that the properties of the encapsulated class have been successfully obtained

How to achieve encapsulation?

The above is the detailed content of How to achieve encapsulation?. 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function