package day12.t1.encap;
public class TestEncapsulation {
public static void main(String[] args) {
Student s1 = new Student();
s1.name="tom";
s1.setAge(22); //传参到setAge
//s1.age =2000;
s1.sex="male";
s1.score=99.9;
System.out.println(s1.getAge()); //调用setAge
}
}
class Student{
String name;
private int age; //私有变量,本类可见。其他位置不可见
String sex;
double score;
public Student() {
}
//为age赋值
public void setAge(int age) {
this.age =age;
}
//age返回值
public int getAge() {
return this.age;
}
}