Java Tricky Question: Why Does This Static Field Print 0 When 42 Is Assigned Right Next to It?
java
dev.to
Here is a scenario that has burned many Java developers during interviews and in real code reviews. The scenario A class initializes one static field from another: public class StaticOrder { static int a = getValue(); static int b = 42; static int getValue() { return b; } public static void main(String[] args) { System.out.println("a = " + a); System.out.println("b = " + b); } } What does it print? a = 42, because b is ass