• 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

Dan exam doubt in arrays

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


How come the answer is 112

Could anyone help me understanding this example ?
 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try compiling the code..
even i thought answer "b" becoz.. of the dimensional difference..
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then you should have told answer f ...

 
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot...that was a very good explanation..
 
Onion rings are vegetable donuts. Taste this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic