用JAVA编写一个学生类,要求创建学生对象,对各属性赋值并输出信息

2024-10-29 01:24:52
推荐回答(1个)
回答1:

package Test;

import java.util.Date;

public class test {

public static void main(String[] args) {
Student stu=new Student();
stu.setName("zhangsan");
stu.setAge(18);
stu.setBirthday(new Date().toString());
System.out.println(stu);
}

}

class Student{
private String name;
private int age;
private String birthday;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}

public String toString(){
return "name="+name+"\tage="+age+"\tbirthday"+birthday;
}

}