日期:2014-05-18 浏览次数:20694 次
public class Student {
private String name;
private Integer age;
private Integer score;
public Student(String name, Integer age, Integer score) {
super();
this.name = name;
this.age = age;
this.score = score;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Integer getScore() {
return score;
}
public void setScore(Integer score) {
this.score = score;
}
/**
* @param args
*/
public static void main(String[] args) {
//1、通过“通过 new Student("张三", 22, 95) 的方式创建对象”
Student student = new Student("张三",22,95);
System.out.println(student.getName());
System.out.println(student.getAge());
System.out.println(student.getScore());
System.out.println("=============================");
//2、通过“可以通过set和get方法访问成员变量” 设置变量并且访问变量
student.setName("李四");
student.setAge(23);
student.setScore(96);
//3、通过get访问
System.out.println(student.getName());
System.out.println(student.getAge());
System.out.println(student.getScore());
}
}