• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Confusion about array instance  RSS feed

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • 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
Java Mac Safari
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
You are welcome!
 
Morning came much too soon and it brought along a friend named Margarita Hangover, and a tiny ad.
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!