Where would variables initialized in initialization blocks be used? Since the scope would be resolved to the block only, these variables cannot be used outside I believe.
Where would variables initialized in initialization blocks be used? Since the scope would be resolved to the block only, these variables cannot be used outside I believe.
Larsen
Hello Larsen, I recommend you write a test program and do some 'trial-and-error' coding it is a good way to resolve such doubts.
HtH
Ikpefua
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
John Jai
Rancher
Joined: May 31, 2011
Posts: 1372
posted
0
Variables declared or initialized in instance block? variables declared within it's scope can be used for computations = normal to what you use local variables in a method.
Larsen Raja
Ranch Hand
Joined: Nov 28, 2011
Posts: 57
posted
0
I tried using such variables outside the block, say another method. But this brings up compilation error. The variable cannot be resolved outside the init block.
Which is exactly what you'd expect from any local variable - the scope is limited to the block they are declared in.
Dennis Deems
Ranch Hand
Joined: Mar 12, 2011
Posts: 547
posted
0
Ikpefua Jacob-Obinyan wrote:
Larsen Raja wrote:Hi,
Where would variables initialized in initialization blocks be used? Since the scope would be resolved to the block only, these variables cannot be used outside I believe.
Larsen
Hello Larsen, I recommend you write a test program and do some 'trial-and-error' coding it is a good way to resolve such doubts.