aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Dan exam doubt in arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Dan exam doubt in arrays" Watch "Dan exam doubt in arrays" New topic
Author

Dan exam doubt in arrays

Soumy Kumar
Ranch Hand

Joined: Nov 02, 2004
Posts: 78


How come the answer is 112

Could anyone help me understanding this example ?


SCJP 1.4<br />" Something is difficult doesn't mean you shouldn't try, it only means you should try harder "
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
I think the answer should be b

BTW what is 112 .
Soumy Kumar
Ranch Hand

Joined: Nov 02, 2004
Posts: 78
try compiling the code..
even i thought answer "b" becoz.. of the dimensional difference..
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Then you should have told answer f ...

Animesh Shrivastava
Ranch Hand

Joined: Jul 19, 2004
Posts: 298
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

Joined: Nov 02, 2004
Posts: 78
thanks a lot...that was a very good explanation..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dan exam doubt in arrays