Java Final Exam Review

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Viet Ho
Viet Ho, Software development
Viet, a versatile software developer, proficient in the development stack, excels in front-end with Svelte, TypeScript, and JavaScript. He's skilled in CSS, CSS libraries, Spring framework, Java, Golang, and MySQL. He thrives in Agile teamwork.
Quizzes Created: 2 | Total Attempts: 397
Questions: 19 | Attempts: 274

SettingsSettingsSettings
Java Final Exam Review - Quiz

Spring 2017. Made by Viet Ho
Saint Paul College | Minnesota


Questions and Answers
  • 1. 

    The constructor in the SeparateIterator class

    • A.

      Initializes the iterator so it begins at the first entry in the list

    • B.

      Connects the iterator to the list in question

    • C.

      Both a & b

    • D.

      None of the above

    Correct Answer
    C. Both a & b
    Explanation
    The constructor in the SeparateIterator class initializes the iterator so it begins at the first entry in the list and connects the iterator to the list in question. This means that when the SeparateIterator object is created, it is set to point to the first entry in the list and is ready to iterate through the elements of the list. Therefore, the correct answer is both a & b.

    Rate this question:

  • 2. 

    A separate class iterator is a good choice when

    • A.

      An ADT’s implementation does not have an iterator and cannot be altered

    • B.

      An ADT’s implementation does not have an iterator and can be altered

    • C.

      An inner class iterator is too difficult to implement

    • D.

      None of the above

    Correct Answer
    A. An ADT’s implementation does not have an iterator and cannot be altered
    Explanation
    When an ADT's implementation does not have an iterator and cannot be altered, a separate class iterator is a good choice. This allows for the creation of a new class specifically designed to iterate over the ADT's elements without modifying its implementation. This approach ensures that the original ADT remains unchanged while still providing the functionality of iteration.

    Rate this question:

  • 3. 

    In the IteratorForLinkedList class, the hasNext method determines iteration has ended by

    • A.

      Checking if the node count is zero

    • B.

      Check if the nextNode variable is null

    • C.

      Setting a special boolean flag to true

    • D.

      Setting a special boolean flag to false

    Correct Answer
    B. Check if the nextNode variable is null
    Explanation
    The correct answer is to check if the nextNode variable is null. This is because in a linked list, each node has a reference to the next node in the list. So, if the nextNode variable is null, it means that there are no more nodes left to iterate over, indicating that the iteration has ended.

    Rate this question:

  • 4. 

    What does the hasNext method return when the list is empty?

    • A.

      False

    • B.

      True

    • C.

      Null

    • D.

      0

    Correct Answer
    A. False
    Explanation
    The hasNext method returns false when the list is empty because there are no elements in the list to iterate over.

    Rate this question:

  • 5. 

    In the ListIteratorForArrayList class, the remove method throws an IllegalStateExeption when

    • A.

      The next method was not called just before it

    • B.

      The previous method was not called just before it

    • C.

      Remove has been called since the last call to next or previous

    • D.

      All of the above

    Correct Answer
    D. All of the above
    Explanation
    The remove method in the ListIteratorForArrayList class throws an IllegalStateException when any of the following conditions are met: the next method was not called just before it, the previous method was not called just before it, or remove has been called since the last call to next or previous. This means that if any of these conditions are true, calling the remove method will result in an IllegalStateException being thrown. Therefore, the correct answer is "all of the above".

    Rate this question:

  • 6. 

    Writing “? super T” where T defines a generic type means

    • A.

      Any super class of T

    • B.

      Any subclass of T

    • C.

      Any composed class of T

    • D.

      It is an illegal expression

    Correct Answer
    A. Any super class of T
    Explanation
    Writing "? super T" where T defines a generic type means that the type parameter T can be replaced with any super class of T. This allows for flexibility in the type hierarchy, as any super class of T can be used in place of T. This is useful when defining generic methods or classes that need to accept a wide range of types.

    Rate this question:

  • 7. 

    To prevent a subclass from overriding protected methods, we declare them to be

    • A.

      Protected

    • B.

      Final

    • C.

      Private

    • D.

      Limited

    Correct Answer
    B. Final
    Explanation
    Final keyword is used in Java to prevent a method from being overridden in a subclass. When a method is declared as final, it cannot be modified or overridden by any subclass. In the given question, the correct answer is "final" because it is the keyword that prevents a subclass from overriding protected methods. Protected methods can still be accessed by subclasses, but if they are declared as final, they cannot be overridden.

    Rate this question:

  • 8. 

    Which method is declared to be protected in the LinkedChainBase class?

    • A.

      AddFirstNode

    • B.

      AddAfterNode

    • C.

      RemoveAfterNode

    • D.

      All of the above

    Correct Answer
    D. All of the above
    Explanation
    The correct answer is "all of the above" because all three methods - addFirstNode, addAfterNode, and removeAfterNode - are declared as protected in the LinkedChainBase class. Being declared as protected means that these methods can only be accessed within the class itself and its subclasses, providing encapsulation and allowing for controlled access to these methods.

    Rate this question:

  • 9. 

    Assume you have an array of unsorted items that allows duplicate entries and that the item you aresearching for is present. Using an iterative sequential search on an unsorted array, the loop exits when

    • A.

      It locates the first entry in the array that matches the item being searched for

    • B.

      It located the last entry in the array that matches the item being searched for

    • C.

      When it reaches the end of the array

    • D.

      None of the above

    Correct Answer
    A. It locates the first entry in the array that matches the item being searched for
    Explanation
    In an iterative sequential search on an unsorted array, the loop exits when it locates the first entry in the array that matches the item being searched for. This means that as soon as a match is found, the loop stops and the search is considered successful. The search does not continue to find any other matching entries in the array.

    Rate this question:

  • 10. 

    Given the following array, how many comparisons to an array entry are performed to search for the number13 if you use the binary search algorithm?

    • A.

      1

    • B.

      2

    • C.

      6

    • D.

      12

    Correct Answer
    A. 1
    Explanation
    In binary search, the algorithm compares the target value with the middle element of the array. If the target value is smaller, it continues the search on the left half of the array; if it is larger, it continues on the right half. In this case, the target value is 13. The algorithm compares it with the middle element, which is 6. Since 13 is greater than 6, the algorithm continues the search on the right half. There is only one comparison made in this process, which is comparing 13 with 6. Therefore, the answer is 1.

    Rate this question:

  • 11. 

    Classes that implement the Comparable interface must define

    • A.

      Equals

    • B.

      LessThan

    • C.

      CompareTo

    • D.

      NotEquals

    Correct Answer
    C. CompareTo
    Explanation
    Classes that implement the Comparable interface must define the compareTo method. This method is used to compare objects of the class and determine their order. It returns a negative integer if the current object is less than the object being compared, zero if they are equal, and a positive integer if the current object is greater. The other methods mentioned (equals, lessThan, notEquals) are not required by the Comparable interface and may or may not be implemented depending on the specific needs of the class.

    Rate this question:

  • 12. 

    Given a table size of 19 the hash function h(k) = k % table size, what index does the entry 24 map to?

    • A.

      5

    • B.

      4

    • C.

      19

    • D.

      24

    Correct Answer
    A. 5
    Explanation
    The given hash function uses the modulo operator to calculate the index. In this case, the entry 24 will be divided by the table size (19) and the remainder will be taken. The remainder of 24 divided by 19 is 5. Therefore, the entry 24 maps to index 5 in the table.

    Rate this question:

  • 13. 

    If you use quadratic probing for collision resolution, it is recommended that the hash table be

    • A.

      Less than half full

    • B.

      More than half full

    • C.

      Almost empty

    • D.

      Extended to use buckets

    Correct Answer
    A. Less than half full
    Explanation
    When using quadratic probing for collision resolution in a hash table, it is recommended to keep the hash table less than half full. This is because quadratic probing can lead to clustering, where consecutive collisions occur in close proximity to each other. If the table is too full, the likelihood of clustering increases, which can negatively impact the performance of the hash table. By keeping the table less than half full, it allows for a better distribution of the elements and reduces the chances of clustering.

    Rate this question:

  • 14. 

    Hashing is a good technique for implementing a dictionary when _____ is the primary task.

    • A.

      Sorting

    • B.

      Searching

    • C.

      Adding entries

    • D.

      Removing entries

    Correct Answer
    B. Searching
    Explanation
    Hashing is a good technique for implementing a dictionary when searching is the primary task because it allows for efficient retrieval of data. Hashing involves using a hash function to map keys to indexes in an array, making it easy to locate the desired value by directly accessing the corresponding index. This results in constant time complexity for searching, making it an ideal choice for scenarios where quick retrieval of data is required.

    Rate this question:

  • 15. 

    Nodes that are children of the same parent node are called _____.

    • A.

      Roots

    • B.

      Ancestors

    • C.

      Descendants

    • D.

      Siblings

    Correct Answer
    D. Siblings
    Explanation
    Nodes that are children of the same parent node are called siblings. Siblings share the same parent node and are at the same level in the tree structure. They are connected through their common parent and do not have any direct hierarchical relationship with each other. Therefore, the correct answer is siblings.

    Rate this question:

  • 16. 

    A node with no children is called a(n) _____.

    • A.

      Leaf

    • B.

      Parent

    • C.

      Both a & b

    • D.

      None of the above

    Correct Answer
    A. Leaf
    Explanation
    A node with no children is called a leaf because it is the end point of a tree branch. It does not have any child nodes branching off from it, hence it is referred to as a leaf node.

    Rate this question:

  • 17. 

    A tree in which each node may have at most two children is called a(n) _____ tree.

    • A.

      General

    • B.

      Binary

    • C.

      Bi-lingual

    • D.

      N-ary

    Correct Answer
    B. Binary
    Explanation
    A tree in which each node may have at most two children is called a binary tree. In a binary tree, each node can have either zero, one, or two children. This type of tree is commonly used in computer science and data structures. The term "binary" refers to the fact that each node has two possible children.

    Rate this question:

  • 18. 

    A node in a binary tree is an object that references a data object and

    • A.

      Two child nodes in a tree

    • B.

      A linked list containing the child nodes

    • C.

      A vector containing the list of child nodes

    • D.

      None of the above

    Correct Answer
    A. Two child nodes in a tree
    Explanation
    A node in a binary tree is an object that references a data object and two child nodes in a tree. In a binary tree, each node can have at most two child nodes, commonly referred to as the left child and the right child. These child nodes can also be considered as separate nodes in the tree. Therefore, the correct answer is that a node in a binary tree references two child nodes in a tree.

    Rate this question:

  • 19. 

    In a binary tree, if both the left and right child of a node are null

    • A.

      The node contains the key-value pair being searched for

    • B.

      The node is invalid

    • C.

      The node is a leaf

    • D.

      The node is the root of the tree

    Correct Answer
    C. The node is a leaf
    Explanation
    If both the left and right child of a node in a binary tree are null, it means that the node does not have any further child nodes. This indicates that the node is a leaf node, which is a node that does not have any children. Therefore, the correct answer is that the node is a leaf.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 20, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • May 14, 2017
    Quiz Created by
    Viet Ho
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.