Tag: An object array of Java
package com;/** * Student * */public class Student {private String name;private int age;public student () {}public student (String name,int age) {this.name = name;this.age = age;} Public string getname () {return name;} Public void setname (string name) {this.name = name;} Public int getage () {return age;} Public void setage (int age) {this.age = age;} @Overridepublic string tostring () {return "student [name=" + name + ", age=" + age + "]";}} package com;/** * I have 5 students, please store the information of these 5 students in an array, and iterate through the array to get to each student information * student: student * member variable:name,age * Construction method: No parameter, parameter * member Method: Setter/getter method * analysis: &NBSP;*&NBSP;1. Create student class * 2. create student array (object Array) &NBSP;*&NBSP;&NBSp; 3. Create 5 Student objects and assign a value of * 4. put the 3-step element into the array * 5. iterate through the student array * */public class objectarraydemo {public static void main (String [] args) {//create A student array student[] stus = new student[5];//create 5 student objects and assign values student Stu1 = new student ("brigitte", 27); Student stu2 = new student ("wind qing", 30); Student stu3 = new student ("elina", 30); Student stu4 = new student ("gigi", 60); Student stu5 = new student ("leehom wang", 35);//store student objects in an array stus[0] = stu1;stus[1] = stu2;stus[2] = stu3;stus[3] = stu4;stus[4] = stu5;for (int i = 0; i < stus.length; i++) {system.out.println ("student information:" +stus[i]);}}} Student Information: student [name= brigitte, age=27] student information: Student [name= Feng yang, age=30] student information: student [name= elina, age=30] Student information:student [name= gigi, age=60] student information: student [name= Leehom wang, age=35]
650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M02/88/B5/wKiom1f_dXCCWI5iAABOcXjpr5c117.png "title=" Qq20161013195024.png "alt=" wkiom1f_dxccwi5iaabocxjpr5c117.png "/>
This article is from the "11831428" blog, please be sure to keep this source http://11841428.blog.51cto.com/11831428/1861633
An array of objects in Java