Self-Assessment Exercises
Chapter 10:
Introduction to Arrays
1.
Which of the following is true about arrays?
a.
Array elements are always primitive types.
b.
Arrays can be passed to methods.
c.
When you instantiate an array of objects, the objects are instantiated automatically.
d.
You must use the keyword
new
to create an array.
2.
You create an array with the following statement. What is the first and last index (offset)?
int[] intArray = new int[10];
a.
0, 9
b.
0, 10
c.
1, 9
d.
1, 10
3.
Which of the following expressions correctly determines the number of elements in the array
intArray
from the previous question?
a.
intArray.length
b.
intArray.length()
c.
intArray.size()
d.
sizeof( intArray )
4.
A cast is ________.
a.
another name for an array
b.
a collection of objects
c.
a conversion from one type to another
d.
only useful for broken arms
5.
Which of the following is true about the
NumberFormat
class?
a.
It is in the
java.text
package.
b.
It makes numbers easier to read by adding commas to separate the thousands place.
c.
You must instantiate
a NumberFormat
object before you can use the
format()
method.
d.
All of the above