用JAVA编写一个学生类,要求创建学生对象,对各属性赋值并输出信息
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;
}
}
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;
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询