class Homework1_Student {
public static void main(String[] args) {
Student s = new Student();
s.setName("张珊");
s.setAge(23);
System.out.println(s.getName() + " " + s.getAge());
Student s1 = new Student("刘文秀",23);
System.out.println(s1.getName() + " " + s1.getAge());
}
}
class Student {
private String name;
private int age;
public Student() {} //无参构造
public Student(String name,int age) { //有参构造
this.name = name;
this.age = age;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setAge(int age) {
this.age = age;
}
public int getAge() {
return age;
}
}
|
|