public class AQuestion { private int i = giveMeJ(); private int j = 10;
private int giveMeJ() { return j; } public static void main(String args[]){ System.out.println((new AQuestion()).i); } } why i am getting 0 as output.what is happened here?
thanks in advance
Anto Telvin Mathew<br />Many of the life failures are people who did not realize how close they were to success when they give up. EDISON
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35256
7
posted
0
Because the initializations of the fields are done in the order in which they appear in the source code. So "i" is initialized before "j", and at the time of the initialization, "j" still has its default value (which is 0).