File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

instance of an array

 
Venkat Ramsimha
Ranch Hand
Posts: 127
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 300
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic