The problem is your cast to Persoon
is being applied to rij.get(i).getNaam()
, not to rij.get(i)
.
What you want is:
((Persoon)rij.get(i)).getNaam()
etc
Or more simply:
for(int i = 0; i < 3; i++){
Persoon p = rij.get(i);
System.out.println(p.getNaam() + " " + p.getVoornaam() + " " + p.getLeeftijd());
}
The parentheses matter. You have know exactly what you're casting and when.