• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

variables in initialization blocks.

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

HtH

Ikpefua
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


Larsen.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which is exactly what you'd expect from any local variable - the scope is limited to the block they are declared in.
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

HtH

Ikpefua


Good to see you back again, Ikpefua
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic