Java OCA OCP Practice Question 342

Question

What will the following code print?

int [] myArray1 =  { 1, 2, 3, 4, 5, 6}; 
int [] myArray2 =  { 0, 0, 0, 0, 0, 0}; 
System .arraycopy (myArray2, 2, myArray1, 3, 2); 
for (int i  :  myArray2) 
    System .out.print (i); 

Select 1 option

  • A. 123006
  • B. 000000
  • C. 000450
  • D. It throw an exception at run time.


Correct Option is  : B

Note

The arraycopy() method basically copies an array from the specified source array, beginning at the specified position, to the specified position of the destination array.

The last parameter is the number of elements that you want to copy.




PreviousNext

Related