Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Confusion about array instance

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Which two create an instance of an array? (Choose two)



Answer: A, D

How option D is creating an instance of Array.Please Explain.

Thanks,
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An array is an object. So a reference to an array can be assigned to a variable of type Object.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by yogi maheshnath:
Hi,

Which two create an instance of an array? (Choose two)



Answer: A, D

How option D is creating an instance of Array.Please Explain.

Thanks,




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 };

I understand the following from the above choices

A. int[] ia = new int[15] -> This is correct

B. float fa = new float[20] -> This is incorrect, missing box brackets, the correct definition is
float[] fa = new float[20],

C. char[] ca = "Some String"

Please explain

D. Object oa = new float[20];

Please explain

E. int ia[][] = { 4, 5, 6, }, { 1, 2, 3 }; - > It should be declared like this ...
int[][] multiD = {
{ 1, 2, 3, 4 },
{ 5, 6, 7 }
};


Thanks
 
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
char[] ca = "Some String"


"Some string" is a String and not an array of Characters.
It should be represented by

char[] ca={ 's','o','m','e','s','t','r','i','n','g','s'}.


And since array is an object, then you can assign it to the variable of type Object.
I dont know how to further explain this.
 
Avi Sridhar
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nabila Mohammad:
char[] ca = "Some String"


"Some string" is a String and not an array of Characters.
It should be represented by

char[] ca={ 's','o','m','e','s','t','r','i','n','g','s'}.


And since array is an object, then you can assign it to the variable of type Object.
I dont know how to further explain this.



Thanks for your eply. explanation is good enough.

Some things needs to be memorized here..
 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are welcome!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic