新建一個類
類必須有以下特點:
1,必須是共有類
2,提供共有的不帶引數的預設的構造方法
3,屬性私有
4,熟悉使用setter/getter封裝
生成一個程式碼如下:
import java.util.Date; //學生類 public class Students { //必須是共有類 //提供共有的不帶引數的預設的構造方法 //屬性私有 //熟悉使用setter/getter封裝 private int sid;//學號 private String sname;//姓名 private String gender;//性別 private Date birthday;//出生日期 private String address;//地址 public Students() { } public Students(int sid, String sname, String gender, Date birthday, String address) { //super(); this.sid = sid; this.sname = sname; this.gender = gender; this.birthday = birthday; this.address = address; } public int getSid() { return sid; } public void setSid(int sid) { this.sid = sid; } public String getSname() { return sname; } public void setSname(String sname) { this.sname = sname; } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } public Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { this.birthday = birthday; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } @Override public String toString() { return "Students [sid=" + sid + ", sname=" + sname + ", gender=" + gender + ", birthday=" + birthday + ", address=" + address + "]"; } }