• 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

static block

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Temp
{
public static void main(String... s)
{
int a[]=new int[10];
a[2]=1000;
System.out.println(a[2]);
}
}

here in the static block we are dynamically initialising the array so i wanted to know that how can we dynamically intialise the array in the static block and same is applicable for when we create the reference id inside the static block
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

abhinav sood wrote:class Temp
{
public static void main(String... s)
{
int a[]=new int[10];
a[2]=1000;
System.out.println(a[2]);
}
}

here in the static block



"Static block"? I assume you mean the main() method. That's not a static block.

we are dynamically initialising the array so i wanted to know that how can we dynamically intialise the array in the static block and same is applicable for when we create the reference id inside the static block



Not sure what you're asking here, unless maybe the very first "static block" was just a typo, and you're asking how to initialize an array in a real static initializer block. If that's your question, it would be like this:


(Note that it's preferable to use int[] a rather than int a[], since it keeps the type ("array of int") part of the declaration together. It's also more common, so more people are used to reading it that way and will find it easier to read if you follow the convention.)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic