题目如下:
package y_Student;
public class Student {
private int id;
private String name;
private int isMale;
private String birth;
//自动生成的getter/setter方法
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getIsMale() {
return isMale;
}
public void setIsMale(int isMale) {
this.isMale = isMale;
}
public String getBirth() {
return birth;
}
public void setBirth(String birth) {
this.birth = birth;
}
//自动生成的完全构造方法
public Student(int id, String name, int isMale, String birth) {
super();
this.id = id;
this.name = name;
this.isMale = isMale;
this.birth = birth;
}
//自动生成的代码框架
@Override
public String toString() {
return "Student [id=" + id + ", name=" + name + ", isMale=" + isMale + ", birth=" + birth + ", getId()="
+ getId() + ", getName()=" + getName() + ", getIsMale()=" + getIsMale() + ", getBirth()=" + getBirth()
+ ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()=" + super.toString()
+ "]";
}
}
package y_Student;
public class StudentTest {
public static void main(String[] args) {
Student student1 = new Student(1,"Niko",1,"2004年4月1日");
System.out.println(student1.toString());
System.out.println();
System.out.println("修改内容后的内容如下:");
System.out.println();
student1.setName("Mary");
student1.setIsMale(0);
student1.setId(2);
student1.setBirth("2004年1月11日");
System.out.println(student1.toString());
}
}
运行结果如下:
其中自动生成的部分具体操作可参考: