class Student
{
String name ;
int age;
}
class Demo
{
public static void main(String[] args)
{
系统添了一个无参的构造方法.
Student stu = new Student();
stu.name = "小红";
stu.age = 21;
Student stu1 = new Student();
stu1.name = "小明";
stu1.age = 19;
Student stu2 = new Student();
stu2.name = "小王";
stu2.age = 20;
Student[] arr = new Student[3];
arr[0] = stu;
arr[1] = stu1;
arr[2] = stu2;
for(int i = 0 ; i <arr.length ; i++){
Student s = arr[i];
System.out.println(s.name +"---"+s.age);
}
}
}
|
|