package com;
public class Student {
private String no;
private String name;
private byte sex;
private int age;
private static int count;
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
public String getName() {
return name;
public void setName(String name) {
this.name = name;
public byte getSex() {
return sex;
public void setSex(byte sex) {
this.sex = sex;
public int getAge() {
return age;
public void setAge(int age) {
this.age = age;
public Student(String no, String name, byte sex, int age) {
super();
count++;
public Student() {
public void print(){
System.out.println("Student物件一共建立了:"+count+"次");
//測試方法
public static void main(String[] args) {
Student[] stus = new Student[5];
for (int i = 0; i < stus.length; i++) {
stus[i] = new Student("NO_"+i,"學生_"+i,(byte)1,22);
stus[i].print();
package com;
public class Student {
private String no;
private String name;
private byte sex;
private int age;
private static int count;
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public byte getSex() {
return sex;
}
public void setSex(byte sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Student(String no, String name, byte sex, int age) {
super();
this.no = no;
this.name = name;
this.sex = sex;
this.age = age;
count++;
}
public Student() {
super();
count++;
}
public void print(){
System.out.println("Student物件一共建立了:"+count+"次");
}
}
//測試方法
public static void main(String[] args) {
Student[] stus = new Student[5];
for (int i = 0; i < stus.length; i++) {
stus[i] = new Student("NO_"+i,"學生_"+i,(byte)1,22);
stus[i].print();
}
}