<<  < 2016 - >  >>
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30




Student类:

public class Student {
private String name;
private int age;
public void say(){
System.out.println("名字:"+name+","+"年龄:"+age);
};
public void setName(String _n){
this.name=_n;
}
public String getName(){
return this.name;
};
public void setAge(int _a){
this.age=_a;
}
public int getAge(){
return this.age;
};
}

测试:MainDao类
public class MainDao {
   public static void main(String ages[]){
 Student s=new Student();
 s.setName("Jack");
 s.setAge(23);
 s.say();
   }
}

  • 标签:Java的访问器 
  • 发表评论:
    天涯博客欢迎您!