This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi everyone, I came upon this piece of code in Kathy sierra, wasn't able to make much sence of it so thought of asking, could anyone tell me why SOP(1) gives an object while SOP(2) gives null, actually the piece of code:instance1.instance2 is not clear to me, the code is as follows:
Q6 q1 = new Q6(); calls the first constructor, which does nothing. As such, q1.qInstance never gets anything assigned to it.
Now the rule is, any field (not local variable!) that never gets a value assigned will get a default value - null for objects. Since q1.qInstance never gets anything assigned to it, it will remain null.