File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Explain this code about Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Explain this code about Arrays" Watch "Explain this code about Arrays" New topic
Author

Explain this code about Arrays

Rashid Mian
Ranch Hand

Joined: Feb 14, 2007
Posts: 31

Why above code gives comiplation error?
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
The line b[] = null doesn't make sense. You don't declare what b is, and you don't give a name to the array.
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364

a and b aren't the same type, see the compilation error that I got

a is int[]
b is int[][]
Anton Uwe
Ranch Hand

Joined: Jan 10, 2007
Posts: 122
b is a reference to a two-dimensional int array, a is a reference to a one-dimensional int array. You cannot assign a one-dim-array to a two-dim-array reference. So, "b=a" will raise a compile error.
chintan ramavat
Ranch Hand

Joined: Sep 15, 2006
Posts: 134
You cannot do int i, j,k ; ===> ( int i, int j, int k)

i think your array B is not making any sense like is it integer or any reference variable.

int [] a ;
int [] b ; would be valid with valuse ==> NULL
Jesse Custer
Ranch Hand

Joined: Feb 07, 2007
Posts: 45
The code you wrote is the same as this:



So now it's easier to see that a is a one-dime,sional array and b a 2-dimensional array. So Carol had it right.

Grtz


PS: In the K&B Book is stated that 'int[] a' is the same as 'int a[]'. This is not exactly correct. Although you will get the same result in this simple case, the difference is, that when you put the brackets before the name (next to the declared type), they will count for any variable you declare on that line. If you put the brackets after the name, they will only count for that specific variable.
[ February 15, 2007: Message edited by: Jesse Custer ]
 
wood burning stoves
 
subject: Explain this code about Arrays
 
Similar Threads
Assigining Null TO Strings
Which one is faster (before writing metric code)
how to avoid displaying 'null' in jsp
NullPointerException in PreparedStatement...
array declaration