Moyen 5 questions

QCM - Subsection 7.8: Indentation (Partie 4)

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 4)

5 questions | Difficulté: moyen


Question 1

What is the purpose of the ‘getTimeout()’ method in the given code?

  • A. It returns a random number between 1 and 20
  • B. It initializes an executor service
  • C. It logs a message to the console
  • D. It waits for a specified timeout
Voir la réponse

Réponse correcte: A

The ‘getTimeout()’ method returns a random number between 1 and 20.


Question 2

What is the role of the lambda expression in the given code?

  • A. It initializes an executor service
  • B. It defines a task that will sleep for a specified timeout
  • C. It logs messages to the console
  • D. It returns a random number between 1 and 20
Voir la réponse

Réponse correcte: B

The lambda expression defines a task that will sleep for a specified timeout.


Question 3

Why can’t variables used inside a lambda expression be modified?

  • A. Because they are final or effectively final
  • B. Because they are not accessible within the scope of the lambda expression
  • C. Because they can only be used with primitive types
  • D. Because they must always return a value
Voir la réponse

Réponse correcte: A

Variables used inside a lambda expression must be final or effectively final.


Question 4

Why is it incorrect to use ’==’ to compare Integer objects?

  • A. Because the ‘equals()’ method should always be used instead
  • B. Because you should never compare objects in Java
  • C. Because you can only compare primitive types
  • D. Because there are no differences between ’==’ and ‘equals()’ when comparing Integers
Voir la réponse

Réponse correcte: A

You should use the ‘equals()’ method instead of ’==’ to compare Integer objects.


Question 5

Why is it a pitfall to use ’==’ for comparing primitive wrapper objects such as Integer?

  • A. Because the ‘equals()’ method should always be used instead
  • B. Because you can only compare primitive types in Java
  • C. Because there are no differences between ’==’ and ‘equals()’ when comparing Integers
  • D. Because it is not possible to use ’==’ with wrapper objects
Voir la réponse

Réponse correcte: A

You should use the ‘equals()’ method instead of ’==’ for comparing primitive wrapper objects such as Integer.