• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dan exam doubt in arrays

 
Soumy Kumar
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


How come the answer is 112

Could anyone help me understanding this example ?
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the answer should be b

BTW what is 112 .
 
Soumy Kumar
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try compiling the code..
even i thought answer "b" becoz.. of the dimensional difference..
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you should have told answer f ...

 
Animesh Shrivastava
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that array implicitly implements Cloneable and Serializable interface

Another thing to remember is that all array of prmitives extends Object class and all arrays of references extends Object[] class

Now regarding ur problem,
This what is the intended meaning when u do a clone on the given array
Object[] obj = (Object[])a.clone(); -----:


Now when u do :

1st pass of for loop---> int[] ia = (int[])obj[0]// which is {1,2}
SOP(ia[0]) // which is 1

2nd pass of for loop---> int[] ia = (int[])obj[1]// which is {0,1,2}
SOP(ia[1]) // which is 1

3rd pass of for loop---> int[] ia = (int[])obj[2]// which is {-1,0,2}
SOP(ia[2]) // which is 2


Hope u r clear now
 
Soumy Kumar
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot...that was a very good explanation..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic