• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

instance of an array

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 can't take it! You are too smart for me! Here is the tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic