Java exam
Mcqs 7- ?
Q7:
Suppose A is an interface, B is a class that realizes interface A, and C is a class that extends class B.
Consider the following code:
Which of the test () method statements will print true to standard output?
Reminder: The java.lang.Object.getClass () method returns the runtime class of an object.
Q8:
Which ArrayList declaration is appropriate for a list that contains values of type float?
Q9:
What does the following method do in the context of a simply linked list?
. The method removes all nodes from the linked list.
. The method traverses the linked list without modifying it.
. The method reverses the linked list.
. The method removes every other node from the linked list.
Q10:
Suppose we have a single-linked sorted list whose nodes contain integer values. What is the mystery () method for in the following code snippet?
Question 10 options:
.The method removes every other node from the linked list.
.This method removes duplicates from the linked lis
.The method traverses the linked list without modifying it.
Q11:
Complete lines 27 and 28 of the following implementation (blanks 1 and 2) so that addLast (E value) adds a value to the end (back) of the doubly linked list.
Q12:
Consider the following doubly linked list. The values saved in the list are integers.
Now, suppose we run the tweak () method, shown below, on this doubly linked list.
Starting from the node designated by head, how will the values of the nodes be read after executing tweak ()?
Q13:
Consider a simply linked list. We want to write a private recursive method, E size (Node <E> current), to calculate the size of the list starting with the node designated by head via the public E size () method (also shown in the snippet below).
Which of the following choices corresponds to a correct implementation of the E size (Node <E> current) method?
Q13 options :
Q14:
The following List interface declares a subset of the methods of the java.util.List interface.
public interface List <E> {
void add ( int index , E elem ) ;
E remove (int index ) ;
boolean remove (E obj ) ;
int size ( ) ;
boolean isEmpty ( ) ;
//autres méthodes
}
For implementing this interface using an array, ArrayList.
Question 14 options:
.Insertions at intermediate positions in the list are always quick.
.Removing an item is always quick.
.Consulting the intermediate positions of the list is always fast.
.none of the above
Q15:
Consider the following simply chained list (the values stored in the list are of type String).
What values will be stored in the list read from left to right after calling the mystery (head, "C") method, shown below, from the list above?