Discussion
How do you instantiate an array in Java?
Answer: C
Correct answer: int arr[] = new int[3];
In Java an array object is created with new followed by the type and the length in square brackets: int arr[] = new int[3];. Round brackets after a type mean a constructor call, and int is a primitive with no constructor. int arr[]; alone only declares the reference - no array exists until new runs.
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