78.8k views
5 votes
An array of stringobjects that will hold 5 names would be declared using which statement?

A) string names[5];
B) string names(5);
C) string names5;
D) String[5] names;
E) None of these will work.

User Mcfinnigan
by
3.3k points

2 Answers

5 votes

Answer:

E) None of these will work

Step-by-step explanation:

Considering the syntax of option (A), it is similar to how to declare an array of string objects in C++. That would have been the correct answer except that the keyword string should have begun with a capital letter. i.e it should be String not string.

Also considering the syntax of option (D), it is similar to how to declare an array of string objects in C++. That would have been the correct answer except that the array name names should be before the number of elements the array will hold. i.e String names [5] rather than String [5] names

Other options are off the point

User Pruthvi Kumar
by
3.2k points
3 votes

Answer:

E) None of these will work

Step-by-step explanation:

Option A, string names[5] will not work because the keyword String is not properly capitalized. Generally, arrays are declared and initialized. This is accomplished in Java Programming language with the new keyword or by assigning initial values to the array in a pair of braces. A valid declaration and initialization for the above question will be any of these two;

String [ ] names = new String [5];

String [ ] namesTwo = {"John", "James", "Jonathan","John", "Jabez"};

In the first example a new array object is created with the new keyword with a provision to hold five elements

In the second example the array is created and and assigned five elements.

User Mlosev
by
3.4k points