ExamVeda
Login
Home
1
In Java, arrays are objects of which class?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
2
How do you declare a one-dimensional array in Java?
Discuss
Answer & Solution
Answer: Option A
Solution:
In Java, a one-dimensional array is declared by specifying the type of elements followed by square brackets and then the array name. The correct syntax is:
type[] arrayName;
Option A follows this syntax and is the correct way to declare a one-dimensional array in Java.
Option B is also a valid syntax but is less commonly used. Both Option A and Option B are equivalent.
Option C is incorrect as it attempts to use generics syntax, which is not allowed for arrays in Java.
Option D is incorrect because Option C is not a valid way to declare an array.
3
What is the default initial value of numeric elements in an array of type int in Java?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
4
What is the correct way to initialize a two-dimensional array in Java?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
5
What does the length attribute of an array in Java represent?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
6
How do you access an element in a one-dimensional array named myArray at index 3 in Java?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
7
What happens if you try to access an array element at an index that is out of bounds in Java?
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
8
Which method is used to find the length of an array in Java?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
9
What is the highest index of an array with 10 elements in Java?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
10
Which of the following is a valid declaration and initialization of a String array in Java?
Discuss
Answer & Solution
Answer: Option D
Solution:
Option A initializes a String array named "names" with three elements: "Alice", "Bob", and "Charlie".
This is a valid and commonly used syntax for declaring and initializing a String array in Java.

Option B: String names[] = new String[]{"Alice", "Bob", "Charlie"};
This syntax is also valid for declaring and initializing a String array in Java. However, it's less commonly used.

Option C: String[3] names = {"Alice", "Bob", "Charlie"};
This syntax is invalid. In Java, when declaring an array, the size should not be specified in the square brackets.