• 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

Array declaration

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi , the below code doesn't give any compilation errors
what does the JVM do for this line "int[] a,c,d[];" what does each variable assigned to

class Q3
{
public static void main(String arg[])
{
int[] a,c,d[];
int b[]=new int[0];
}
}
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Raj Kumar:
Hi , the below code doesn't give any compilation errors
what does the JVM do for this line "int[] a,c,d[];" what does each variable assigned to



"a" and "c" are int arrays. "d" is an array of int arrays. And like all local variables, they need to be assigned, before they are allowed to be used.

Henry
 
Raj Kumar
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks hendry,

i just splited the line like this
int[] a,c;
int[]d[];

i got a clear ans...

thanks a lot
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Raj Kumar:

i just splited the line like this
int[] a,c;
int[]d[];


I think for most Java programmers, the preferred syntax would be (1) one variable definition per line and (2) writing the array brackets next to the type, not to the right of the variable name:

int[] a;
int[] c;
int[][] d;
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic