Home  >  Article  >  Java  >  What does set in java mean?

What does set in java mean?

little bottle
little bottleOriginal
2019-05-24 13:53:3217547browse

set in java represents the setting method, which is used to set data. When using the set method in a class, set and get are followed by some specific words to form a method name with a specific meaning, such as setName, setAge, etc.

What does set in java mean?

#Obviously to answer this question, we need to understand encapsulation. Encapsulation is the basis for ensuring that software components have excellent modularity. The goal of encapsulation is to achieve "high cohesion and low coupling" of software components and prevent the impact of changes caused by program interdependence. In object-oriented programming languages, objects are the most basic unit of encapsulation. Object-oriented encapsulation is clearer and more powerful than encapsulation in traditional languages.

(Video tutorial recommendation: java course)

In order to achieve encapsulation, member variables of the class are often declared as private, and then the variable is accessed through the public method for a visit.

So what should we do when we want to operate these variables? ?

Methods to operate variables enclosed within a class:

<1>Through the public constructor ------ -Assign a value to the variable once the object has been instantiated.

<2>Through the set and get methods

set is for setting, and get is for obtaining. These two methods are for data processing Used for setting and getting.

Moreover, when using set and get methods in a class, set and get are followed by some specific words to form method names with specific meanings, such as set xxx () and get xxx (), means setting xxx and getting xxx.

Related recommendations: java introductory tutorial

The above is the detailed content of What does set in java mean?. 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