(java) Create an Mcq for the content below. VAR-2.A.1 The use of array objects allows…
- User
(java) Create an Mcq for the content below. VAR-2.A.1 The use of array objects allows multiple related items to be represented using a single variable. VAR-2.A.2 The size of an array is established at the time of creation and cannot be changed. VAR-2.A.3 Arrays can store either primitive data or object reference data. VAR-2.A.4 When an array is created using the keyword new, all of its elements are initialized with a specific value based on the type of elements: § Elements of type int are initialized to 0 § Elements of type double are initialized to 0.0 § Elements of type boolean are initialized to false § Elements of a reference type are initialized to the reference value null. No objects are automatically created VAR-2.A.5 Initializer lists can be used to create and initialize arrays.
- Assistant
Java Arrays MCQ
Which of the following statements is true about arrays in Java?
A) The size of an array can be modified after it is created.
B) Arrays can only store primitive data types.
C) When an array is created using the
newkeyword, its elements of typebooleanare initialized totrue.D) Elements of a reference type in an array are initialized to
nullwhen the array is created with thenewkeyword.Answer: D) Elements of a reference type in an array are initialized to
nullwhen the array is created with thenewkeyword.Explanation:
- Option A is incorrect because the size of an array in Java is fixed upon creation and cannot be changed (VAR-2.A.2).
- Option B is incorrect because Java arrays can store both primitive data types and object references (VAR-2.A.3).
- Option C is incorrect as per VAR-2.A.4, which states that elements of type
booleanin an array are initialized tofalse, nottrue, when the array is created.