创建一个引用类型数组对象,并赋值
//学生类
public class Student { //Student是我们自己创建的一种数据类型
//创建成员变量
String name; //姓名
int age; //年龄
String address; //地址
//创建构造方法----创建目的是:初始化成员变量
Student(String name,int age,String address){
this.name = name;
this.age = age;
this.address = address;
}
Student(){
this("无名氏",25,"河北邯郸");
}
//学习行为
void study(){
System.out.println(name+"在学习");
}
//打招呼行为
void sayHi(){
System.out.println("大家好,我叫"+this.name+"我今年"+this.age+"岁了,家住"+this.address);
}
}
public class StudentTest{ //创建一个学生类
public static void main(String[] args){
Student[] stus = new Student[3]; //声明一个Student数组stus,包含3个元素,每个元素都是Student类型,默认值为null
stus[0] = new Student();
stus[1] = new Student();
stus[2] = new Student();
}
}
}