Discussion
Which line contains the error?
public class Sample80
{
public static void main(String[] args)
{
int[] src = {1, 2, 3};
int[] dst = new int[2];
assert src.length == dst.length;
System.arraycopy(src, 0, dst, 0, src.length);
}
}
Answer: D
The assertion states something that is plainly false for these arrays, so it fires immediately under -ea and hides the real problem. Without assertions the copy throws ArrayIndexOutOfBoundsException, which is the actual bug: the destination is too small. The check should compare the length being copied against the destination.
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