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.
The varaibles declared in static or instance initialization blocks will cease to exists once the block completes execution. Thanks Deepak
SCJP, SCWCD, SCBCD
Satish K Patil
Joined: Jun 24, 2007
But, Instance init blocks are used as a place to put code that all constructors in a class share. can you just please give eg for it. Here, when i try to print 'x'. it prints 0. why not 999 ? [ August 05, 2007: Message edited by: Satish K Patil ]
when i try to print 'x'. it prints 0. why not 999 ?
That is because you have two different 'x' variables in your class. The first is the static variable that didn't get initialized, and hence, has the value of zero. And the second is the local variable declared in your initializer, which has already been mentioned, went out of scope, after it has been set to 999.