hi As per JLS The static initializers and class variable initializers are executed in textual order. so when static int i is get initialized by calling getK(), static int k has NOT been initialized as it comes after var 'i', so it has a default value of '0', which get perinted. HTH
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
Hi Rajiv, you correctly pointed out the output of the above code, but I am not sure of the explanation as yet. By "textual order" do we mean that i will be initialized before k, provided both are static? if so, why just putting k=99 above the i=getK() method initialized i to 99? Could you elaborate a little, Thanks!
Anup, The variables will be initialized by order of execution one line at a time, ie. line of code on top first then line of code below after. This must be what others refer to as "textual order" it does not mean alphabetical order. So when you assign a variable to a literal then call a method after, it works as expected, but when you call the method before the variable has been initialized to a literal you get omething else. That's because the default of zero is substituted in the variable inside the method since it has not been declared and initialized yet. Does this help? Ask again if not. Cheers,
<a href="http://www.ajmasters.com" target="_blank" rel="nofollow">http://www.ajmasters.com</a> Real Estate, Tampa Florida
Joined: Mar 04, 2002
That does help Mario..the "textual order" confused me..but now I understand it. Cheers!
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com