Java基础知识英语选择题6——Array, Vector, ArrayList

1. Consider the Java program below.

public class Arr{
    public static void main(String[] args) {
        int[] a = {1, 2, 3};

        System.out.println(a[1]);
        System.out.println(a[3]);
    }
}

Which of the following is true about the result of executing the program?

A. The number 2 is printed and a run-time exeception terminates execution.

B. The number 2 is printed and there is no abnormal termination.

C. The number 1 is printed and there is no abnormal termination.

D. The number 3 is printed and a run-time exeception terminates.

Correct Answer: A

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

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

 A. 2

B. 0

C. 1

D. 45

Correct Answer: C

3. A Java array that contains n components will be indexed from through___.

A. 0, n-1

B. 1, n

C. 0, n

D. 1, n-1

Correct Answer: A

4. 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: A

5. 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. Ⅱ only

B. Ⅰonly

C. Ⅲ only

D. Ⅰand Ⅲ only

Correct Answer: D

6. An object that contains methods that traverse an vector linearly from start to finish is known as a(n)____.

A.loop

B. iterator

C. int

D. Exception

Correct answer: B

7. The class java.util.ArrayList implements a collection that

A. cannot be accessed using an integer index

B. can only store instances of the class java.lang.String

C. can grow to accommodate new items

D. can only store primitive variables such as int or boolean

Correct Answer: C

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. Ⅲ only

B. Ⅰ and Ⅲ only

C. Ⅰonly

D.  Ⅰ, Ⅱ and Ⅲ

Correct Answer: D

9. Consider the following method call, where v is an instance of the class java.util.Vector

v.size();

This method call returns the number of ____

A. bytes used by v

B. times that the method v.add has been called

C. Vector objects that have been instantiated

D. elements in the vector represented bt v

Correct Answer: D

10. Array elements may only be retrieved using___, whereas vector elements may also be retrieved using____.

A. indexes, iterators

B. iterators, indexs

C. names, indexes

D. indexes, names

Correct Answer: A

(部分题目来自网络,如有侵权,请联系文章作者删除)

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值