SSD3 : Multiple-Choice Quiz 4

本文详细解析了Java中数组的使用方法与特性,包括数组的初始化、索引访问等,并对比介绍了ArrayList的特点与操作方式,如元素添加、索引访问及迭代器的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

rel="File-List" href="file:///D:%5CAppData%5CLocal%5CMICROS%7E1%5CTEMP%5Cmsohtmlclip1%5C01%5Cclip_filelist.xml"> rel="themeData" href="file:///D:%5CAppData%5CLocal%5CMICROS%7E1%5CTEMP%5Cmsohtmlclip1%5C01%5Cclip_themedata.thmx"> rel="colorSchemeMapping" href="file:///D:%5CAppData%5CLocal%5CMICROS%7E1%5CTEMP%5Cmsohtmlclip1%5C01%5Cclip_colorschememapping.xml">

rel="File-List" href="file:///D:%5CAppData%5CLocal%5CMICROS%7E1%5CTEMP%5Cmsohtmlclip1%5C01%5Cclip_filelist.xml"> rel="themeData" href="file:///D:%5CAppData%5CLocal%5CMICROS%7E1%5CTEMP%5Cmsohtmlclip1%5C01%5Cclip_themedata.thmx"> rel="colorSchemeMapping" href="file:///D:%5CAppData%5CLocal%5CMICROS%7E1%5CTEMP%5Cmsohtmlclip1%5C01%5Cclip_colorschememapping.xml">


         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)

        

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值