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 following code in from exercise of K&B . The answer shows that it might throw Nullpointer exception as well as program might hang without ever completing.
I don't understand why it will throw Null Pointer Exception. All though answer explains since Integer i is not initialized it.. But according to my knowledge instance variables are assigned value '0' .
Paul might be slightly pickily distinguishing between '0' and 0 (), but he's right that this is not what happens. Reference member variables get initialised to null if a value isn't specified, and Integer is a reference variable.
Joined: Jul 15, 2010
Thanks Paul and Matthew
Is it that the program would have run fine if instead of Integer we had int as instance variable?