QCM - Section 4: The comparison is then carried out as follows (Partie 19)
Quiz interactif avec 5 questions. Testez vos connaissances!
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 - Section 4: The comparison is then carried out as follows (Partie 19)
5 questions | Difficulté: moyen
Question 1
What does the code in CrazyStrings class print?
- A. “hello”
- B. “you stink!”
- C. 42
- D. An error
Voir la réponse
Réponse correcte: B
The code modifies the value of a String object’s internal ‘value’ field using reflection. The modified string is printed.
Question 2
What does the code in CrazyMath class print?
- A. 1
- B. 42
- C. An error
- D. The output depends on the JVM’s behavior
Voir la réponse
Réponse correcte: C
The code modifies the value of an Integer object using reflection. The modified integer is then printed.
Question 3
What does the code in Evil class do?
- A. It initializes a Boolean with true value
- B. It re-initializes a final variable
- C. It prints ‘Everything is false’
- D. None of the above
Voir la réponse
Réponse correcte: C
The code uses reflection to modify the value of the ‘FALSE’ constant in the Boolean class and also removes its final modifier. This behavior can cause unexpected issues in the JVM.
Question 4
What is the output of the ReflectionDemo program?
- A. A.name=StackOverFlow
- B. A.age=20
- C. A.rep=New Reputation
- D. A.count=25
Voir la réponse
Réponse correcte: A
The code uses reflection to access and modify private variables of the A class object.
Question 5
What is a common danger when misusing Reflection API?
- A. Modifying constants
- B. Accessing private variables
- C. Changing final variables
- D. None of the above
Voir la réponse
Réponse correcte: D
Misuse of the Reflection API can lead to unexpected behavior in the JVM, such as modifying constants, accessing private variables, and changing final variables.