Kamis, 13 April 2017

MIDTERM TES 3


  Section 1
  (Answer all questions in this section)
 
  1.   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

 
  2.   Unit testing is the phase in software testing in which individual software modules are combined and tested as a whole. True or false?  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Correct

 
  3.   Which of the following statements is false?  Mark for Review
(1) Points
 
 
An ArrayList can grow and shrink dynamically as required.

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

 
An ArrayList can store multiple object types.

 
An ArrayList has a fixed length. (*)

 
  Correct

 
  4.   Which of the following statements about unit testing is/are true
I. When all unit tests succeed, you can have high confidence your code is solid.
II. If a unit test fails, you donメt proceed until the code is fixed and the test succeeds.
III. If all unit tests succeed, you should continue writing new tests until you break the code.  Mark for Review
(1) Points
 
 
I only

 
I and II only

 
II and III only (*)

 
I, II, and III

 
None of the above

 
  Correct

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

Section 1
  (Answer all questions in this section)
 
  6.   When all unit tests succeed, you can have high confidence your code is solid. True or false?  Mark for Review
(1) Points
 
 
True (*)

 
False

 
  Correct

 

 
  Section 2
  (Answer all questions in this section)
 
  7.   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

 
  8.   Virtual method invocation requires that the superclass method is defined as which of the following?  Mark for Review
(1) Points
 
 
A default final method.

 
A public static method.

 
A private final method.

 
A public method. (*)

 
A public final method.

 
  Correct

 
  9.   An abstract class can implement its methods.  Mark for Review
(1) Points
 
 
True (*)

 
False

 
  Correct

 
  10.   The instanceof operator works inside an if statement.
True or false?  Mark for Review
(1) Points
 
 
True (*)

 
False

 
  Correct

11.   You can't downcast an object explicitly because you must use virtual method invocation. True or false?  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Incorrect. Refer to Section 2 Lesson 2.

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

 
False (*)

 
  Correct

 
  13.   The instanceof operator works with class instances and primitive data types.
True or false?  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Incorrect. Refer to Section 2 Lesson 2.

 
  14.   Calling a subclass method by referring to a superclass works because you have access to all specialized methods through virtual method invocation.
True or false?  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Correct

 
  15.   < ? > is an example of a bounded generic wildcard.  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Incorrect. Refer to Section 2 Lesson 3.

 
16.   A generic class is a type of class that associates one or more non-specific Java types with it. The types are determined when an object of that class is created.  Mark for Review
(1) Points
 
 
True (*)

 
False

 
  Incorrect. Refer to Section 2 Lesson 3.

 
  17.   What is the correct definition of Enumeration (or enum)?  Mark for Review
(1) Points
 
 
A list of elements that is dynamically stored.

 
A bounded generic class

 
A keyword that specifies a class whose objects are defined inside the class. (*)

 
Code that initializes an ArrayList

 
  Correct

 
  18.   A generic class increases the risk of runtime class conversion exceptions.  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Correct

 
  19.   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

 
  Incorrect. Refer to Section 2 Lesson 6.

 
  20.   Which of the following best describes lexicographical order?  Mark for Review
(1) Points
 
 
The order of indicies after an array has been sorted.

 
An order based on the ASCII value of characters. (*)

 
A simple sorting algorithm that is inefficient on large arrays.

 
A complex sorting algorithm that is efficient on large arrays.

 
  Correct

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

 
False (*)

 
  Correct

 
  22.   Big-O Notation is used in Computer Science to describe the performance of Sorts and Searches on arrays. True or false?  Mark for Review
(1) Points
 
 
True (*)

 
False

 
  Correct

 
  23.   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

 
  Incorrect. Refer to Section 2 Lesson 6.

 
  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

 
  Incorrect. Refer to Section 2 Lesson 6.

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

 
False (*)

 
  Incorrect. Refer to Section 2 Lesson 6.

26.   Which of the following sorting algorithms utilizes a "divide and conquer" technique to sort arrays with optimal speed?  Mark for Review
(1) Points
 
 
Sequential Search

 
Merge Sort (*)

 
Selection Sort

 
Binary Search

 
All of the above

 
  Incorrect. Refer to Section 2 Lesson 6.

 
  27.   Of the options below, what is the fastest run-time?  Mark for Review
(1) Points
 
 
log(n) (*)

 
n

 
n*log(n)

 
n^2

 
  Incorrect. Refer to Section 2 Lesson 6.

 
  28.   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.

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

 
False (*)

 
  Correct

 
  30.   What is the correct way to initialize a HashSet?  Mark for Review
(1) Points
 
 
HashSet classMates =
new HashSet(); (*)

 
ClassMates = public class
HashSet();

 
classMates = new HashSet[String]();

 
String classMates = new
String();

 
  Incorrect. Refer to Section 2 Lesson 4.

31.   Which of the following correctly adds "Cabbage" to the ArrayList vegetables?  Mark for Review
(1) Points
 
 
vegetables += "Cabbage";

 
vegetables.get("Cabbage");

 
vegetables.add("Cabbage"); (*)

 
vegetables[0] = "Cabbage";

 
  Correct

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

 
False (*)

 
  Incorrect. Refer to Section 2 Lesson 4.

 
  33.   A collection is an interface in the Java API.  Mark for Review
(1) Points
 
 
True (*)

 
False

 
  Incorrect. Refer to Section 2 Lesson 4.

 
  34.   Which class is an ordered collection that may contain duplicates?  Mark for Review
(1) Points
 
 
array

 
set

 
enum

 
list (*)

 
  Incorrect. Refer to Section 2 Lesson 4.

 
  35.   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

36.   A method with default access can be subclassed.
True or false?  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Correct

 
  37.   Making a class immutable means.  Mark for Review
(1) Points
 
 
To create a sub class from a parent class

 
To create an instance of the class.

 
That it cannot be extended. (*)

 
That it is directly subclassed from the Object class

 
  Correct

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

 
False (*)

 
  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.   Which one of the following statements is true?  Mark for Review
(1) Points
 
 
A class is an intance of an object

 
A class is a Java primitive

 
A Java program can only contain one super class

 
A class is a template that defines the features of an object (*)

 
  Incorrect. Refer to Section 2 Lesson 1.

41.   Immutable classes can be subclassed.
True or false?  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Correct

 
  42.   Modeling classes for a business problem requires understanding of the business not Java. True or false?  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Correct

 
  43.   A LinkedList is a type of Stack  Mark for Review
(1) Points
 
 
True (*)

 
False

 
  Incorrect. Refer to Section 2 Lesson 5.

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

 
False

 
  Incorrect. Refer to Section 2 Lesson 5.

 
  45.   A HashMap can only store String types.  Mark for Review
(1) Points
 
 
True

 
False (*)

 
  Correct

46.   A LinkedList is a list of elements that is dynamically stored.
True or false?  Mark for Review
(1) Points
 
 
True (*)

 
False

 
  Correct

 
  47.   What are maps that link a Key to a Value?  Mark for Review
(1) Points
 
 
Arrays

 
ArrayLists

 
HashSets

 
HashMaps (*)

 
  Incorrect. Refer to Section 2 Lesson 5.

 
  48.   The Comparable interface defines the compareTo method.  Mark for Review
(1) Points
 
 
True (*)

 
False

 
  Incorrect. Refer to Section 2 Lesson 5.

 
  49.   Why can a LinkList be considered a stack and a queue?  Mark for Review
(1) Points
 
  (Choose all correct answers)
 
 
Because you can add elements to the end of it. (*)

 
Because you can remove elements from the end of it. (*)

 
Because you can add element to the beginning of it. (*)

 
Because you can remove elements from the beginning of it. (*)

 
  Incorrect. Refer to Section 2 Lesson 5.

 
  50.   The Comparable interfaces defines a method called compareTo.  Mark for Review
(1) Points
 
 
True (*)

 
False

 
  Incorrect. Refer to Section 2 Lesson 5.

What is the correct way to initialize a HashSet?  Mark for Review
(1) Points
 
 
HashSet classMates =
new HashSet(); (*)

 
classMates = new HashSet[String]();

 
ClassMates = public class
HashSet();

 
String classMates = new
String();

 
  Incorrect. Refer to Section 2 Lesson 4.

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

 
False

 
  Incorrect. Refer to Section 2 Lesson 2.


 
  20.   Abstract classes define what?  Mark for Review
(1) Points
 
 
All methods with implementations

 
Some methods with implementations (*)

 
Constants and all methods with implementations

 
Variables and methods

 
All method definitions without any implementations

 
  Incorrect. Refer to Section 2 Lesson 2.

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 (*)

 
  Incorrect. Refer to Section 2 Lesson 1.

29.   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.

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

 
False (*)

 
  Incorrect. Refer to Section 2 Lesson 3.

 
45.   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.

 
  Incorrect. Refer to Section 2 Lesson 6.


0 komentar:

Posting Komentar

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