File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes output of this program? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "output of this program?" Watch "output of this program?" New topic
Author

output of this program?

Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113
hi ranchers
i have the following code :

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: 42374
    
  64
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).


Ping & DNS - my free Android networking tools app
Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113
thank you very much
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: output of this program?