wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes instance of an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "instance of an array" Watch "instance of an array" New topic
Author

instance of an array

Venkat Ramsimha
Ranch Hand

Joined: Dec 28, 2004
Posts: 127
Which two create an instance of an array?
A. int[] ia = new int [15];
B. float fa = new float [20];
C. char[] ca = "Some String";
D. Object oa = new float[20];
E. Int ia [][] = (4, 5, 6) (1, 2, 3)

Answer: A, D

Hi All,
how is the above possible?

Thanks,
venkat
soumya ravindranath
Ranch Hand

Joined: Jan 26, 2001
Posts: 300
Hi,

I presume that your confusion is regarding the answer D. An array is an object, as is specified in

Arrays (JLS 2nd Edition)



In the Java programming language arrays are objects (�4.3.1), are dynamically created, and may be assigned to variables of type Object (�4.3.2). All methods of class Object may be invoked on an array.


- Soumya.
[ May 13, 2005: Message edited by: soumya ravindranath ]
nitin goswami
Greenhorn

Joined: Mar 01, 2005
Posts: 25
All kind of Arrays are of type Object whether its an arrray of primitives or an array of any kind of references ie.Integer[],String []..etc.
int[] number= new int[10];
(number instanceof Object) will result in true.
But Make Sure that arrays are treated Specially in Java i.e. You cant extend Array and you cant override methods of the Object class via array.
->One more thing Arrays are always created in Heap not in Stack.No matter the array is of primitive type variables.
->int [] intArray;
byte[] byteArray;
intArray=byteArray \\Wrong...the byte is assignable to int but references of these type 's arrays are not.
-Nitin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: instance of an array