Discussion
What will be the output of the program?
public class Listing37
{
Listing37()
{
int[] src = {1, 2, 3, 4};
int[] dst = new int[4];
System.arraycopy(src, 1, dst, 0, 2);
System.out.println(dst[0] + " " + dst[1] + " " + dst[2]);
}
public static void main(String[] args)
{
new Listing37();
}
}
Answer: A
The call copies 2 elements starting at index 1 of the source into index 0 of the destination, so 2 and 3 land in the first two slots. Everything else keeps the default value for an int array, which is 0. The arguments run source, source position, destination, destination position, length.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development