Different output after main class execution

public class Main {
    public static void main(String[] args){
        System.out.println(X.Y.Z);
    }
}

class X {
    static class Y {
        static String Z = "Result 1";
    }
    static C Y = new C();
}

class C {
    String Z = "Result 2";
}  

The output is time "Result 1", and sometimes "Result 2". Can you explain why?

I use JDK 1.6_33.

+5
source share
1 answer

This is Java Puzzler # 68 - it should always print Result 2. Quote:

, , . , [JLS 6.5.2]. , , [JLS 6.3.2]. , . , , , , .

+9

All Articles