跟着老湿写的这个多态练习,父类Person,子类Student、Teacher。在主函数中创建test方法,用来判断对象运行类型并进行相应转型,然后调用对应方法。可是在main函数末尾创建test方法时,一直报错,提示需要)什么的,见图如下,蒙圈中,救我
```java
package homework13;
public class HomeWork13 {
public static void main(String[] args) {
Person[] persons = new Person[4];
persons[0] = new Student("池池", '女', 37, "011000001259");
persons[1] = new Student("会会", '女', 35, "011000008888");
persons[2] = new Teacher("顺顺", '男', 45, 19);
persons[3] = new Teacher("平平", '男', 39, 25);
System.out.println("排序前:");
for(int i = 0; i < persons.length; i++) {
persons[i].info();
}
Person temp = null;
for (int i = 0; i < persons.length - 1; i++) {
for (int j = 0; j < persons.length - 1-i; j++) {
if(persons[j].getAge() > persons[j+1].getAge()){
temp = persons[j];
persons[j]=persons[j+1];
persons[j+1]=temp;
}
}
}
System.out.println("排序后:");
for (int i = 0; i < persons.length; i++) {
persons[i].info();
}
public void test(Person p){
if(p instanceof Student){
((Student)p).study();
}
if(p instanceof Teacher){
((Teacher)p).teach();
}
System.out.println("传参错误");
}
}
}
```