aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes initializing multidimensional array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "initializing multidimensional array" Watch "initializing multidimensional array" New topic
Author

initializing multidimensional array

Vaibhav Chauhan
Ranch Hand

Joined: Aug 16, 2006
Posts: 115
Read the following code where I have created a multidimensional array of references in which I have not instantiated(commented in the code) the second dimension of array:



here compiler doesn't have any problem but there is runtime exception. My question is that why compiler doesn't complain that we can't use aor[0][0] before instantiating because after instantiating only reference starts pointing null(i.e. at line 1).
[ August 30, 2006: Message edited by: Vaibhav Chauhan ]
Vaibhav Chauhan
Ranch Hand

Joined: Aug 16, 2006
Posts: 115


this code generates compilation error that local variable is not initialised. How the above case is different from this one.
[ August 30, 2006: Message edited by: Vaibhav Chauhan ]
Balasubramani Dharmalingam
Ranch Hand

Joined: Dec 06, 2004
Posts: 116
The elements of the array will be initialized to its default values 0 for primitives , null for Objects ..

Here all the string references are initialized to its default values.Like this
in

aor[0],aor[1]... aor[4] will be initialized to null, when you access anything using null reference NullPointerException will be thrown.


Balasubramani SD,<br />SCJP 1.4,SCWCD 1.4,SCJP 5.0<br /><a href="http://sd.balasubramani.googlepages.com" target="_blank" rel="nofollow">www.sd.balasubramani.googlepages.com</a>
 
wood burning stoves
 
subject: initializing multidimensional array