Kamis, 13 April 2017

MIDTERM TES 2

1.   What do Arrays and ArrayLists have in common?
I. They both store data.
II. They can both be traversed in loops.
III. They both can be dynamically re-sized during execution of a program.  Mark for Review
(1) Points
 
 
I only

 
II only

 
I and II only (*)

 
I, II and III only

 
None of the above

 
  Correct

 
  2.   Reading great code is just as important for a programmer as reading great books is for a writer. True or false?  Mark for Review
(1) Points
 
 
True (*)

 
False

 
  Correct

 
  3.   Which of the following statements about arrays and ArrayLists in Java are true?
I. An Array has a fixed length.
II. An Array can grow and shrink dynamically as required.
III. An ArrayList can store multiple object types.
IV. In an ArrayList you need to know the length and the current number of elements stored.  Mark for Review
(1) Points
 
 
I and III only (*)

 
II and IV only

 
I, II, and III only

 
I, II, III and IV

 
None of the above

 
  Correct

 
  4.   Which of the following statements is false?  Mark for Review
(1) Points
 
 
An ArrayList can store multiple object types.

 
An ArrayList can grow and shrink dynamically as required.

 
An ArrayList has a fixed length. (*)

 
In an Array you need to know the length and the current number of elements stored.

 
  Correct

 
  5.   The main purpose of unit testing is to verify that an individual unit (a class, in Java) is working correctly before it is combined with other components in the system. True or false?  Mark for Review
(1) Points
 
 
True (*)

 
False

 
  Correct

6.   Which of the following are important to your survival as a programmer?  Mark for Review
(1) Points
 
 
Being good at reading code.

 
Looking for opportunities to read code.

 
Being good at testing.

 
All of the above. (*)

 
  Correct

 

 
  Section 2
  (Answer all questions in this section)
 
  7.   A LinkedList is a type of Stack  Mark for Review
(1) Points
 
 
True (*)

 
False

 
  Correct

 
  8.   Stacks are identical to Queues  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Correct

 
  9.   Nodes are components of LinkedLists that are like maps because they identify where the next and previous nodes are.
True or false?  Mark for Review
(1) Points
 
 
True (*)

 
False

 
  Correct

 
  10.   These are a list of elements that have a first in last out ordering.  Mark for Review
(1) Points
 
 
HashMaps

 
Stacks (*)

 
Enums

 
Arrays

 
  Correct

11.   Which of the following methods adds a Key-Value map to a HashMap?  Mark for Review
(1) Points
 
 
put(Key, Value) (*)

 
get(Key, Value)

 
remove(Key, Value)

 
add(Key, Value)

 
  Correct

 
  12.   A HashMap can store duplicates.  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Correct

 
  13.   Which of the following correctly defines a queue?  Mark for Review
(1) Points
 
 
A list of elements with a first in first out order. (*)

 
Something that enables you to create a generic class without specifying a type between angle brackets <>.

 
It is a keyword in Java that restrict the use of the code to local users only.

 
A list of elements with a first in last out order.

 
  Correct

 
  14.   To allow our classes to have a natural order we could implement the Comparable interface.  Mark for Review
(1) Points
 
 
True (*)

 
False

 
  Correct

 
  15.   Sets may contain duplicates.  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Correct

16.   What is a set?  Mark for Review
(1) Points
 
 
Something that enables you to create a generic class without specifying a type between angle brackets <>.

 
A collection of elements that does not contain duplicates. (*)

 
A keyword in Java that initializes an ArrayList.

 
A collection of elements that contains duplicates.

 
  Correct

 
  17.   A HashSet is a set that is similar to an ArrayList. A HashSet does not have any specific ordering.
True or false?  Mark for Review
(1) Points
 
 
True (*)

 
False

 
  Correct

 
  18.   The following code is valid when working with the Collection Interface.
Collection collection = new Collection();  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Correct

 
  19.   What is wrong with the following declaration of the ArrayList of strings arr?

ArrayList(String) arr = new ArrayList(String)<>;  Mark for Review
(1) Points
 
  (Choose all correct answers)
 
 
Only the 1st occurrence of "(String)" should be replaced with ""

 
The angled brackets "<>" need to be replaced with parenthesis "()" and parenthesis "()"need to be replaced by "<>" (*)

 
Both occurences of "(String)" should be replaced with "<String>" and the angled brackets "<>" need to be replaced with parenthesis "()" (*)

 
Nothing, this declaration is correct.

 
  Incorrect. Refer to Section 2 Lesson 4.

 
  20.   ArrayList and Arrays both require you to define their size before use.  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Correct

21.   Define a collection.  Mark for Review
(1) Points
 
 
It enables you to create a generic class without specifying a type between angle brackets <>.

 
It is an interface in the java.util package that is used to define a group of objects. (*)

 
It is a special type of class that is associated with one or more non-specified Java type.

 
It is a subclass of List.

 
  Correct

 
  22.   Selection sort is efficient for large arrays. True or false?  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Correct

 
  23.   Selection sort is efficient for large arrays. True or false?  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Correct

 
  24.   Which searching algorithm involves using a low, middle, and high index value to find the location of a value in a sorted set of data (if it exists)?  Mark for Review
(1) Points
 
 
Sequential Search

 
Merge Sort

 
Selection Sort

 
Binary Search (*)

 
All of the above

 
  Correct

 
  25.   Which of the following is the correct lexicographical order for the contents of the int array?

{17, 1, 1, 83, 50, 28, 29, 3, 71, 22}  Mark for Review
(1) Points
 
 
{1, 2, 7, 0, 9, 5, 6, 4, 8, 3}

 
{1, 1, 3, 17, 22, 28, 29, 50, 71, 83}

 
{83, 71, 50, 29, 28, 22, 17, 3, 1, 1}

 
{1, 1, 17, 22, 28, 29, 3, 50, 71, 83} (*)

 
{71, 1, 3, 28,29, 50, 22, 83, 1, 17}

 
  Incorrect. Refer to Section 2 Lesson 6.

26.   A sequntial search is an iteration through the array that stops at the index where the desired element is found. True or false?  Mark for Review
(1) Points
 
 
True (*)

 
False

 
  Correct

 
  27.   Binary searches can be performed on sorted and unsorted data. True or false?  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Correct

 
  28.   Selection sort is a sorting algorithm that involves finding the minimum value in the list, swapping it with the value in the first position, and repeating these steps for the remainder of the list. True or false?  Mark for Review
(1) Points
 
 
True (*)

 
False

 
  Correct

 
  29.   Which of the following is the correct lexicographical order for the contents of the int array {17, 1, 1, 83, 50, 28, 29, 3, 71, 22}  Mark for Review
(1) Points
 
 
{1, 2, 7, 0, 9, 5, 6, 4, 8, 3}

 
{1, 1, 3, 17, 22, 28, 29, 50, 71, 83}

 
{1, 1, 17, 22, 28, 29, 3, 50, 71, 83} (*)

 
{83, 71, 50, 29, 28, 22, 17, 3, 1, 1}

 
{71, 1, 3, 28,29, 50, 22, 83, 1, 17}

 
  Correct

 
  30.   Why might a sequential search be inefficient?  Mark for Review
(1) Points
 
 
It utilizes the "divide and conquer" method, which makes the algorithm more error prone.

 
It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*)

 
It involves looping through the array multiple times before finding the value, which is inefficient on large data sets.

 
It is never inefficient.

 
  Correct

31.   Upward casting an object instance means you can't access subclass specific methods.
True or false?  Mark for Review
(1) Points
 
 
True (*)

 
False

 
  Correct

 
  32.   The instanceof operator only works with class instances.
True or false?  Mark for Review
(1) Points
 
 
True (*)

 
False

 
  Correct

 
  33.   An abstract class can be instantiated.  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Correct

 
  34.   Virtual method invocation must be defined with the instanceof operator. True or false?  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Correct

 
  35.   The instanceof operator enables a method to discover the type of object it was invoked upon. True or false?  Mark for Review
(1) Points
 
 
True (*)

 
False

 
  Correct

36.   A downward cast of a subclass lets you access a subclass specialized method call.
True or false?  Mark for Review
(1) Points
 
 
True (*)

 
False

 
  Correct

 
  37.   A upward cast means all instance variables of the subclass are permanently lost to the instance.
True or false?  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Correct

 
  38.   Virtual method invocation is:  Mark for Review
(1) Points
 
 
Not part of polymorphism.

 
When the method of a superclass is used on a superclass reference.

 
When the method of a subclass is used on a subclass reference.

 
When the method of a subclass is used on a superclass reference. (*)

 
  Correct

 
  39.   You have an interface called Animal.
You wish to create an instance of Animal.
Which one of the following is correct?  Mark for Review
(1) Points
 
 
Animal animal = new Animal();

 
Animal animal = null;

 
Animal animal = new Animal("Bear");

 
None of the other choices. (*)

 
  Incorrect. Refer to Section 2 Lesson 1.

 
  40.   You can only implement one interface in a class.  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Correct

41.   Classes can be made immutable by placing a final key word before all method implementations.
True or false?  Mark for Review
(1) Points
 
 
True (*)

 
False

 
  Correct

 
  42.   Modeling business problems requires understanding the interaction between interfaces, abstract and concrete classes, subclasses, and enum classes.  Mark for Review
(1) Points
 
 
True (*)

 
False

 
  Correct

 
  43.   In general, classes can be made immutable by placing a final key word before the class keyword.
True or false?  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Correct

 
  44.   An interface can implement methods.  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Correct

 
  45.   Making a class immutable means.  Mark for Review
(1) Points
 
 
That it cannot be extended. (*)

 
To create an instance of the class.

 
To create a sub class from a parent class

 
That it is directly subclassed from the Object class

 
  Correct

46.   Interfaces define what?  Mark for Review
(1) Points
 
 
All methods with implementations

 
Variables and methods

 
Constants and all methods with implementations

 
Some methods with implementations

 
All method definitions without any implementations (*)

 
  Correct

 
  47.   Generic methods are required to be declared as static.  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Correct

 
  48.   Which of the following correctly initializes an object named cell of the class Telephones whose generic type is Cellular?  Mark for Review
(1) Points
 
 
Telephones cell = new Telephones(Cellular c);

 
Telephones(Cellular) cell = new Telephones(Cellular);

 
Telephones<> cell = new Telephones<>(Cellular c);

 
Telephones cell = new Telephones(); (*)

 
None of the above.

 
  Correct

 
  49.   When would an enum (or enumeration) be used?  Mark for Review
(1) Points
 
 
When you already know all the possibilities for objects of that class. (*)

 
When you wish to remove data from memory.

 
When you want to be able to create any number of objects of that class.

 
When you wish to initialize a HashSet.

 
  Correct

 
  50.   Generic methods can only belong to generic classes.  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Incorrect. Refer to Section 2 Lesson 3.


3 komentar:

luvne.com ayeey.com cicicookies.com mbepp.com kumpulanrumusnya.com.com tipscantiknya.com