public class Student extends Person{
private String name;
public Student(String name) {
this.name = name;
}
public Student() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Student{" +
"name='" + name + '\'' +
'}';
}
}
public class Test01 {
public static void main(String[] args) {
//java中子类数组的引用可以转换为超类数组的引用,而不需要采用强制类型转换。
Student[] student = new Student[5];
//但是student和objs引用的是同一个对象
Person[] person = student;
//如果试图存储一个Person类型的引用就会引发ArrayStoreException异常
person[0] = new Person();
}
}