java in the get () method and the use of set () method

First of all, see to know the name of Italy, we will first analyze the set and get two words meaning, the meaning is set to set, and get to obtain the meaning of the two methods shows that get () and set () are used to get and set data.

When using the two methods are generally methods are behind plus a word to indicate that will be set or get features such as setAge (), getName () meaning to set an age to get the name.

So why use the set (), get () methods? This would involve the closure and security java language in some classes will need to modify private, so other classes can not access variables inside the class, it improves security

But sometimes we need to use one variable, then how to get it? We say that this time we should use the set () and get () method

for example


Demo {class
// private String, int;
Private String name;
Private int Age;

public String getName () // get method core SET;
{// get the need to extract a return value of String, and int;
return name;
}
void the setName public (n-String)
{
name = n-;
}
public int getAge () {// int return a value Age
return Age;
}
public void the setAge (int Age) {
this.age = Age;
} // SET GET method End

Probably like the

 

Guess you like

Origin www.cnblogs.com/Zhu1316802150/p/11907522.html