JAVA 对象数组的简单应用

public class Studentex{
public static void main(String[] args) {
Student[] student = new Student[3];
student[0] = new Student(11010331,“郑洪”,“男”,20);
student[1] = new Student(11010228,“郑鹏”,“男”,15);
student[2] = new Student(11010221,“郑羽”,“女”,19);
System.out.println("\t学号" + “\t姓名” + “\t性别” + “\t年龄”);
for(int i = 0;i<student.length;i++){
System.out.println();
System.out.println("\t"+student[i].getNumber() + “\t” + student[i].getName() + “\t” + student[i].getSex() + “\t” + student[i].getAge());
}

}

}

public class Student{
private long number;
private String name;
private String sex;
private int age;

public Student(){

}

public Student(long number,String name,String sex,int age){
	this.number = number;
	this.name = name;
	this.sex = sex;
	this.age = age;
}

public long getNumber(){
	return number;
} 

public String getName(){
	return name;
}

public String getSex(){
	return sex;
}

public int getAge(){
	return age;
}

}

猜你喜欢

转载自blog.csdn.net/weixin_44895008/article/details/89422539