Moyen 5 questions

QCM - Subsection 7.8: Indentation (Partie 2)

Quiz interactif avec 5 questions. Testez vos connaissances!

#java

Comment jouer ?

  • 1. Lisez chaque question attentivement
  • 2. Choisissez votre réponse parmi les options
  • 3. Cliquez sur "Voir la réponse" pour vérifier
  • 4. Comptez vos bonnes réponses à la fin !

Quiz: QCM - Subsection 7.8: Indentation (Partie 2)

5 questions | Difficulté: moyen


Question 1

In the CountDownLatchDemo code, what is the purpose of the ‘numberOfThreads’ variable?

  • A. It represents the number of lines in the code
  • B. It defines the number of threads to be created and managed by the CountDownLatch
  • C. It tracks the number of errors that occur during execution
  • D. It specifies the number of pages in the source document
Voir la réponse

Réponse correcte: B

The ‘numberOfThreads’ variable is used to define the number of threads to be created and managed by the CountDownLatch.


Question 2

In the CountDownLatchDemo code, what does the ‘await()’ method do?

  • A. It initializes a new thread
  • B. It increments the counter of threads
  • C. It waits for all the created threads to finish their execution before resuming the main thread
  • D. It prints the current thread name
Voir la réponse

Réponse correcte: C

The ‘await()’ method is used by the main thread to wait for all the created threads to finish their execution before resuming.


Question 3

What is the purpose of the ‘CountAndPrint’ class in the given code?

  • A. It manages a CountDownLatch object
  • B. It defines a Runnable task to be executed by multiple threads
  • C. It represents an exception that can occur during the execution
  • D. It initializes a new thread
Voir la réponse

Réponse correcte: B

The ‘CountAndPrint’ class is defined as a Runnable task to be executed by multiple threads.


Question 4

In the CountAndPrint code, what does the loop in the run() method do?

  • A. It initializes a new thread
  • B. It increments the counter of threads
  • C. It prints the current thread name
  • D. It iterates 10000 times printing the current instance’s name and an index
Voir la réponse

Réponse correcte: D

The loop in the run() method iterates 10000 times, printing the current instance’s name and an index.


Question 5

In the CountAndPrint code, what is the purpose of the ‘main’ method?

  • A. It launches 4 parallel threads for executing the CountAndPrint instances
  • B. It initializes a new thread
  • C. It increments the counter of threads
  • D. It defines the entry point of the Java program
Voir la réponse

Réponse correcte: A

The ‘main’ method is used to launch 4 parallel threads for executing the CountAndPrint instances.