+1 vote
in Data Structures & Algorithms I by (110k points)
How do you instantiate an array in Java?

(a) int arr[] = new int(3);

(b) int arr[];

(c) int arr[] = new int[3];

(d) int arr() = new int(3);

This intriguing question comes from Array and Array Operations in portion Abstract Data Types of Data Structures & Algorithms I

This question was addressed to me at a job interview.

1 Answer

+1 vote
by (412k points)
selected by
Best answer
Correct answer is (c) int arr[] = new int[3];

For explanation: Note that int arr[]; is declaration whereas int arr[] = new int[3]; is to instantiate an array.

Related questions

Welcome to TalkJarvis QnA, a question-answer community website for the people by the people. On TalkJarvis QnA you can ask your doubts, curiosity, questions and whatever going in your mind either related to studies or others. Experts and people from different fields will answer.