public class Student {
private String id;
private String name;
private String profession;
private String major;
public Student(){
}
public Student(String id,String name,String major){
this.id = id;
this.name = name;
this.major = major;
}
public static void main(String[] args) {
Student s = new Student("22222","张三","数学");
System.out.println(s.getId());
s.setName("张三");
System.out.println(s.getMajor());
s.setMajor("英语");
}
//获取学号
public String getId() {
return id;
}
//修改名字
public void setName(String name) {
this.name = name;
}
//获取所修课程
public String getMajor() {
return major;
}
//修改所修课程
public void setMajor(String major) {
this.major = major;
}
}
package ssss;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Student stu = new Student();
//打印信息
stu.info();
//修改学号
stu.setNum(1111);
//获取学号
stu.getNum();
//修改课程
stu.setCou("c语言");
//获取课程
stu.getCou();
}
}
class Student {
private String name="张三";
private int num=10001;
private String pro="计算机";
private String cou="java";
public String getName() {
return name;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
System.out.println("修改学号");
}
public String getPro() {
return pro;
}
public String getCou() {
return cou;
}
public void setCou(String cou) {
this.cou = cou;
System.out.println("修改课程为:"+cou);
}
public Student() {
// TODO Auto-generated constructor stub
}
public void info() {
System.out.println("[name=" + name + ", num=" + num + ", pro=" + pro + ", cou=" + cou + "]");
}
}