Examlex

Solved

Consider the AddFirst Method of the LinkedList Class in Chapter

question 41

Multiple Choice

Consider the addFirst method of the LinkedList class in Chapter 16: /**
Adds an element to the front of the linked list.
@param element the element to add
*/
Public void addFirst(Object element)
{
Node newNode = new Node() ;
NewNode.data = element;
NewNode.next = first;
First = newNode;
}
Three implementations have been proposed to make the addFirst method thread safe where listLock is a variable of type ReentrantLock. Which of them will work?
I.
ListLock.lock() ;
Try
{
Node newNode = new Node() ;
NewNode.data = element;
NewNode.next = first;
}
Finally
{
ListLock.unlock() ;
}
First = newNode;
II.
Node newNode = new Node() ;
NewNode.data = element;
NewNode.next = first;
ListLock.lock() ;
Try
{
First = newNode;
}
Finally
{
ListLock.unlock() ;
}
III.
ListLock.lock() ;
Try
{
Node newNode = new Node() ;
NewNode.data = element;
NewNode.next = first;
First = newNode;
}
Finally
{
ListLock.unlock() ;
}


Definitions:

Nonverbal Messages

Refers to the way people communicate without using words, including gestures, facial expressions, and body language.

Variety of Gestures

The use of physical movements and signs, beyond verbal communication, to convey messages or express thoughts and emotions.

Nonverbal

Pertaining to forms of communication that do not involve speech or written language, such as gestures, facial expressions, and posture.

Vocal Qualities

The characteristics of a person's voice, including tone, pitch, loudness, and expressiveness, which affect how spoken communication is perceived.

Related Questions