This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
This is because you are initializing j after calling the giveMeJ() method. So by the time you call this method j does not have any value except default value 0. If you change private int j = 10 before calling giveMeJ() it prints 10. Please do verify.
Sai Surya, SCJP 5.0, SCWCD 5.0, IBM 833 834
http://sai-surya-talk.blogspot.com, I believe in Murphy's law.
When considering the variables 1- All INSTANCE VARIABLES will have the default value as the zero.
2- All LOCAL VARIABLES (i.e with in the method) should be initialised before use.No default value is allocated for those variables.
If you use the local variables without intialising then you will definitely get error.Similarly if you use the instance variables without intialising then you will not get the error because every instance variables will be having the default values.