class Student {
String name;
boolean isFee = false;// 是否已交学费
// 默认构造器
Student() {
System.out.println(" what a ghost");
}
void fees() {
isFee = true;// 修改是否交学费的状态
}
}
public class studentDemo {
public static void main(String[] args) {
// 创建五个学生对象
Student s1 = new Student();
s1.name = "赵";
Student s2 = new Student();
s2.name = "钱";
s2.isFee = true;
Student s3 = new Student();
s3.name = "孙";
s3.isFee = false;
Student s4 = new Student();
s4.name = "李";
Student s5 = new Student();
s5.name = "周";
System.out.println(s5.isFee);
// 创建数组
Student[] students = new Student[] { s1, s2, s3, s4, s5 };
for (Student s : students) {
System.out.println(s.name + "," + s.isFee);
// 判断学生是否已经缴费
// 如果没有,则调用其缴费方法
if (!s.isFee) {
s.fees();
}
}
System.out.println(s3.isFee);//true
// 集合,数组中存储的元素,都是该对象的引用地址
System.out.println(students[4] == s5);// true
}
}