package langs;
public class Student {
private String sno;
private String name;
private char sex;
private int age;
public Student() {
// TODO Auto-generated constructor stub
}
public Student(String sno, String name, char sex, int age) {
super();
this.sno = sno;
this.name = name;
this.sex = sex;
this.age = age;
}
public String getSno() {
return sno;
}
public void setSno(String sno) {
this.sno = sno;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
package langs;
public class StudentTest {
public static void main(String[] args) {
Student john = new Student("s001","john",'男',24);
Student mark = new Student("s002","mark",'男',25);
System.out.println("john学号: " + john.getSno());
System.out.println("mark学号: " + mark.getSno());
System.out.println("john姓名: " + john.getName());
System.out.println("mark姓名: " + mark.getName());
System.out.println("john年龄: " + john.getAge());
System.out.println("mark年龄: " + mark.getAge());
john.setAge(26);
System.out.println("john年龄: " + john.getAge());
}
}
学生类:
public class Student {
private String num;//学号
private String name;//姓名
private String sex;//性别
private int age;//年龄
public Student(String num,String name,String sex,int age){
this.num = num;
this.name = name;
this.sex = sex;
this.age = age;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
测试类:
public class StudentTest {
public static void main(String[] args) {
Student John = new Student("0000026", "John", "男", 18);//John
Student Mark = new Student("0000027", "Mark", "男", 20);//Mark
System.out.println(John.toString());//显示是输出?
System.out.println(Mark.toString());
John.setAge(22);//修改John年龄
System.out.println("修改后的John:"+John.toString());
}
}
楼主这个太简单了,看看书自己就可以做出来,我在想要不要告诉你,这样会不会对你学习不太好吧。。。
这个是你们老师布置的作业吧。。。。