1.学习封装
package com.msb.test07;
//封装
public class Girl {
private int age;
// 赋值
public void setAge(int age){
if(age > 30){
this.age = 18;
}else{
this.age = age;
}
}
// 读取
public int getAge(){
return age;
}
}
package com.msb.test07;
public class Test {
public static void main(String[] args) {
Girl girl = new Girl();
girl.setAge(28);
System.out.println(girl.getAge());
}
}