SSD3 : MultipleChoice Quiz 4


         1.

Consider the following Java program segment.

String[] str = {"Three","Two","One"};

    for (int i = 0; i < str.length; ++i)  {

    System.out.println(str[i]+"/");

    }

What will be output upon execution of the program segment?

(a) Three/Two/One/

(b) One/Two/Three/

(c) One,Two,Three

(d) Three,Two,One

 

         Correct answer is (a)

         2.   

Regarding the following declaration, what is the index of the element containing 45?

                       int[]  numbers = {-1, 45, 6, 132};

(a) 45

(b) 1

(c) 2

(d) 0

 

         Correct answer is   (b)

         4.   

         If the length of a particular array is the value of LIMIT, what is the index of the last item in that array?   

 

(a) LIMIT

(b) LIMIT / 2

(c) LIMIT - 1

(d) 0

 

         Correct answer is   (c)

         5.

A Java array that contains n components will be indexed from _____ through _____.

(a) 1, n-1

(b) 0, n-1

(c) 1, n

(d) 0, n

 

         Correct answer is   (b)

         6.   

Legal Java statements to initialize an array reference include which of the following?

 

   1. int[] aobj = {0, 1, 2};

   2. int[4] aobj = {0, 1, 2};

   3. int[] aobj = new int[3];

(a) I only

(b) I and II only

(c) III only

(d) I and III only

 

         Correct answer is   (d)

         7.

The class java.util.ArrayList implements a collection that

(a) can only store primitive variables such as int or boolean

(b) can grow to accommodate new items

(c) cannot be accessed using an integer index

(d) can only store instances of the class java.lang.String

 

         Correct answer is   (b)

         8.

In which of the following ways can items be added to a collection implemented by java.util.ArrayList?

 

   1. Items can be inserted at the beginning of the collection.

   2. Items can be inserted between two existing items in the collection.

   3. Items can be appended to the end of the collection.

 

        

 

(a) III only

(b) I and III only

(c) I only

(d) I, II, and III

 

         Correct answer is   (d)

         9.

An object that contains methods that traverse a collection linearly from start to finish is known as a(n)

        

 

(a) Exception

(b) int

(c) loop

(d) iterator

 

         Correct answer is   (d)

         10.

Which of the following statements is not true of the class java.util.ArrayList?

(a) The constructor of the ArrayList class, when called with no arguments, causes an empty ArrayList to be constructed.

(b) An instance of ArrayList can grow to accommodate new items when the collection is full.

(c) Once an object is inserted into an instance of ArrayList, it can never be removed.

(d) Items stored by an instance of ArrayList can be accessed using integer indexes.

 

         Correct answer is   (c)

         2.

Regarding the following declaration, what is the index of the element containing 45?                       int[]  numbers = {-1, 45, 6, 132};

(a) 45

(b) 1

(c) 2

(d) 0

 

         Correct answer is   (b)

         3.

Consider the following Java program segment.

    int[] arr;

    arr = new int[3];

    arr[2]=19;

    arr[1]=17;

    arr[0]=15;

 

Which of the following Java statements is syntactically correct and semantically identical to the program segment?

(a) int[] arr= {15, 17, 19};

(b) int arr[3]= {15, 17, 19};

(c) int[3] arr = {15, 17, 19};

(d) int arr = {15, 17, 19};

 

         Correct answer is (a)

        

 

原文地址:https://www.cnblogs.com/vivizhyy/p/3394910.html