How to create an Array of Object

Is this correct:Object[] anArray = new Object[5]; Thanks.
[91 byte] By [jw2001] at [2007-9-26 2:43:00]
# 1
Well, you could actually try it to find out :P) but yes, that's correct--at least it's correct if what you want is an array of 5 Objects.
jverd at 2007-6-29 10:21:01 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 2
Any suggestions?Thanks
jw2001 at 2007-6-29 10:21:01 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 3
Suggestion -- be specific about what you want to know. We cannot tell you if code is correct if you won't tell us what you want it to do!
schapel at 2007-6-29 10:21:01 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 4

Your code will create an array of 5 null references to class Object. After that line you could code:anArray[0] = new Integer(5);

- or -

Object x = anArray[1];

but if you code:anArray[3].DoSomething();

and have not initialized anArray[3], you will get a NullPointerException.

Doug

DougDean at 2007-6-29 10:21:01 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 5
an arry of 5 null references to class Object!You are good! Since you know what the beginner may not clear about.
james_lixing at 2007-6-29 10:21:01 > top of Java-index,Archived Forums,New To Java Technology Archive...