• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

cannot be accessed out of the static block

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
1.what is the practical use of such a block of code?
public class Test {

static {int a = 5; }
public static void main(String args[]) {
System.out.println(a);//illegal as a cannot be accessed out of the static block
}
}
2. I was checking up Sahir's mock Test applet. He has tested exhaustively on constructors and method signatures i.e what are valid constructors for this class etc. Is it required to be so extensive and perfect in constructors or does a passing glance through them suffice?
Regards,
Kapil
 
kapil apshankar
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Could someone please reply to my questions?
Regards,
Kapil
 
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Usually, java program starts from main block, but if u use static blocks, it will first do the static blocks, and then enter into main block.
In you example, it will first assign a = 5, then prints the value of a.
Vanitha

Originally posted by kapil apshankar:
hi,
1.what is the practical use of such a block of code?
public class Test {

static {int a = 5; }
public static void main(String args[]) {
System.out.println(a);//illegal as a cannot be accessed out of the static block
}
}
2. I was checking up Sahir's mock Test applet. He has tested exhaustively on constructors and method signatures i.e what are valid constructors for this class etc. Is it required to be so extensive and perfect in constructors or does a passing glance through them suffice?
Regards,
Kapil


 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic