public class Girl extends Student{...} //has firstname, lastname, id
public class Student {...}
public class School{
Student[] arr = new girl(firstname, lastname, id)
for(int i = 0; i<arr.length; i++){
arr.getID(); //does this work if I have a getter in Girl class?
}
}
如果我有一个Student对象数组的女孩,是否可以从School类访问该女孩的ID?
最佳答案
你可以检查
if (arr[i] instanceof Girl)
{
Girl girl = (Girl)arr[i];
...