Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
mcq.docx
Скачиваний:
13
Добавлен:
25.02.2016
Размер:
30 Кб
Скачать
☆
    • II only

    • I and II

    • None

    • I only

  • In Java, which of the following is (are) true of both arrays and ArrayList objects?

  • Both use the bracket operator and an index to access individual elements.

  • Both are resizable.

  • Elements are inserted into both with the method add.

    • I only

    • II only

    • III only

    • None

  • What will be output when the following Java program segment is executed?

ArrayList<String> animals = new ArrayList<String>();

animals.add("cat");

animals.add("dog");

for (Iterator<String> i = animals.iterator(); i.hasNext(); ) {

System.out.print(i.next().charAt(0));

}

    • catdog

    • c

    • ca

    • cd

  • What will be output when the following Java program segment is executed?

ArrayList<String> animals = new ArrayList<String>();

animals.add("cat");

animals.add("dog");

animals.add("dog");

for (int i = 0; i < animals.size(); ++i) {

if (animals.get(i).equals("dog")) {

animals.remove(i);

}

}

System.out.println(animals.size());

    • 3

    • 0

    • 1

    • 2

  • What will be output when the following Java program segment is executed?

String[] strings = {"bird", "dog"};

for (int i = strings.length - 1; i >= 0; --i) {

System.out.print(strings[i].length() + " ");

}

    • bird dog

    • dog bird

    • 4 3

    • 3 4

  • In Java, an individual component of an array can be accessed using an index and which of the following operators?

    • ( )

    • .

    • instanceof

    • [ ]

  • Consider the following Java code segment.

int[] foo = new int[5];

At the end of execution of the segment, what will be the value of foo[2]?

    • 2

    • 3

    • null

    • 0

  • A reference variable r in Java can hold a reference to which of the following?

  • An object having the same declared type as r

  • An object of any subclass of the declared type of r

  • An object of any superclass of the declared type of r

    • I, II, and III only

    • I only

    • I and III only

    • I and II only

  • Consider the following Java program segment.

class Aircraft {

void takeOff() {...}

}

class Helicopter extends Aircraft {

void takeOff() {...}

}

...

Helicopter h = new Helicopter();

Aircraft a = new Aircraft();

Aircraft ah = new Helicopter();

Execution of which of the following lines would cause the method takeoff of the class Helicopter to be executed?

  • h.takeOff();

  • a.takeOff();

  • ah.takeoff();

    • I, II, and III

    • I only

    • I and II only

    • I and III only

  • In Java, which of the following can appear in abstract classes but not in interfaces?

  • Definitions of instance variables

  • Implementation of methods

  • Implementation of constructors

    • I only

    • I and II only

    • II and III only

    • I, II, and III

  • In Java, which of the following is (are) true regarding interfaces?

  • An interface can extend a class.

  • An interface can extend multiple interfaces.

    • I only

    • I and II

    • None

    • II only

  • A singleton class typically refers to its instance via a _____ variable.

    • public static

    • private instance

    • public instance

    • private static

  • In singleton classes, the constructor is _____ to ensure that instantiation is controlled through a(n) _____ method.

    • private, instance

    • omitted, static

    • omitted, instance

    • private, static

  • Which of the following is (are) true regarding the strategy design pattern?

  • A family of algorithms are combined into a large single method.

  • Polymorphism is used.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]