Bitte nicht hauen: Anfängerfrage 
Wieso funktionirt folgendes?
Ausgabe:
Wieso funktionirt folgendes?
Code:
import java.util.*;
class X
{
private int a = -1;
public void setA(int neua)
{
a = neua;
}
public int getA()
{
return a;
}
}
public class Y
{
public static void main(String[] args)
{
ArrayList al = new ArrayList();
al.add(new X());
System.out.println("Vorher: " + ((X) al.get(0)).getA() );
((X) al.get(0)).setA(999);
System.out.println("Nachher: " + ((X) al.get(0)).getA() );
}
}
java Y hat gesagt.:Vorher: -1
Nachher: 999