Usage of the private member variable values of protection of java will determine the value of

day02 Package; 

public class Private_yongfa {
String name;
Private int Age; // fixed wording
String Sex;

public void the setAge (int NUM) {// set value, set + initials guard value, the return value does not need to void, is fixed wording
if (NUM <100 && NUM> 0) {
Age = NUM;
} the else {
System.out.println ( "data not Age");
}
}

public int getAge () {// value, get + initials protection value, return type int, return value is needed, the fixed wording
return Age;
}
}
+ ================================= ================================================== =
day02 Package Penalty for; 

public class Private_yong {
public static void main (String [] args) {
Private_yongfa Xinxi = print01 ( "Zhao Liying," 99, "female");
System.out.println ( "name:" + xinxi.name + "Age : "+ xinxi.getAge () +" gender: "+ xinxi.sex); // xinxi.getAge () Gets the value of the fixed wording
}
public static Private_yongfa print01 (String name, int Age, sex String) {
Private_yongfa = new new Xinxi Private_yongfa ();
xinxi.name name =;
xinxi.setAge (Age); // set value, the fixed wording
xinxi.sex = Sex;
return Xinxi;


}
}

Guess you like

Origin www.cnblogs.com/cxycxycxy/p/11762555.html