1按照如下要求定义类
(1)创建一个Student类,成员变量为学号xh,姓名xm,学院xymc,年龄age
(2)提供构造函数public Student(String xhString xm,String xymc,intage),对成员变量进行初始化。(3)提供成员变量对应的get和set方法
(4)在主函数中利用Student类测试,构建对象stu,成员变量初始化为你的个人信息。
(5)对用set方法修改stu对象的学院为“人工智能学院”。
前世今生的有缘人?
class Student {
private String xh;
private String xm;
private String xymc;
private int age;
public Student(String xh, String xm, String xymc, int age) {
super();
this.xh = xh;
this.xm = xm;
this.xymc = xymc;
this.age = age;
}
public String getXh() {
return xh;
}
public void setXh(String xh) {
this.xh = xh;
}
public String getXm() {
return xm;
}
public void setXm(String xm) {
this.xm = xm;
}
public String getXymc() {
return xymc;
}
public void setXymc(String xymc) {
this.xymc = xymc;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "Student [xh=" + xh + ", xm=" + xm + ", xymc=" + xymc + ", age=" + age + "]";
}
}
public class Answer7733445 {
public static void main(String[] args) {
Student stu = new Student(" a", "b ", "c", 1);
stu.setXymc("人工智能学院");
System.out.println(stu);
}
}