Campbell Ritchie wrote:Try it and see what happens.
Compile time error : "the local variable 'event' may not have been initialized"
But, 'event' is initialized inside try-block, then, why this error? And, if the scope of local variable is within the try-block, then, we've declared event outside try-block, can't we just declare outside try-block and initialize inside try-block?
Edit:
So i tried on other blocks than try, like inside for-loop, or some other functional blocks, we have to initialize the local reference variable to NULL, then only we can use that local variable outside the block. Like in the example below :
But, i'm not getting it why we have to initialize the local variable to NULL, as inside the block the reference of that local variable is ultimately given to some other concrete object. Then, why first we are giving reference to NULL??
P.S.: Sorry for grammatical mistakes, m not a native English speaker ;)