Menu
Topics Index
...
`

System Example2575


If you need explanation Read this topic

If you need Answer Take test on this topic

System Example2575
What will be the output of the following program?
public class SystemExample {
    public static void main(String[] args) {
        int a1[] = {0, 1, 2, 3};
        int a2[] = {1, 10, 20, 30};
        System.arraycopy(a1, 0, a2, 0, 5);
        System.out.print("a2 = ");
        System.out.print(a2[0] + " ");
        System.out.print(a2[1] + " ");
    }
}

A. a2 = 0 1
B. a2 = 1 10
C. a2 = 0 10
D. Compilation Error or Runtime Error
Topic: System Class arraycopy() Method In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans : e
array size exceeds

Posted by Sree Priya    2014-04-24 13:37:05


D. Runtime error i.e., exception rises since in arraycopy the no.of elements to copied in the array is given as 5 but the actual number is 4

Posted by Nikhil Sulibhavi    2014-04-24 13:38:56


Answer:D RunTimeError as it is going out of ArrrayBound's at arraycopy()  if it was System.arraycopy(a1,0,a2,0,4); then it would have worked but as per now it will throw a RunTimeError

Posted by Deepak Kumar Yadav    2014-04-24 13:39:15


d because in arraycopy 5 elements are given

Posted by Meghana Trikovala    2014-04-25 04:40:42


Congratulations Nikhil Sulibhavi. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-04-26 05:42:26


© meritcampus 2019

All Rights Reserved.

Open In App