How to move ArrayList with child class

3

Next, I have a ArrayList of type Student (which is an abstract class), and I have two child classes ( EstudanteGraduacao and EstudantePosGraduacao ), when I add them to ArrayList is quiet, but how do I go through it with an object of the daughters?
For example when I do:

for(Estudante e : estudantes){
    return e.getX();
    // considerando getX um metodo de Estudante
}

It works, the problem is that I do not know how to access the methods of EstudanteGraduacao ...

Anyway, I hope it was clear, I appreciate the help

    
asked by anonymous 20.05.2015 / 07:38

1 answer

0

You have to cast for undergraduate student

((EstudanteGraduacao) e).getX()

But be careful, if all students in the array are not StudentGrid, then the getX () method will throw the ClassCastException.

    
20.05.2015 / 08:44