What does the following code print?
public class A { static int x; public static void main(String[] args) { A that1 = new A(); A that2 = new A(); that1.x = 5; //from w w w . j a v a 2s . c om that2.x = 1000; x = -1; System.out.println(x); } }
D.
Since x is static, there is only one variable, which is shared by all instances along with the class.
Thus the last assignment wins.