Bird
0
0

Given the following code snippet in a Spring Boot service:

medium📝 component behavior Q4 of 15
Spring Boot - Advanced Patterns
Given the following code snippet in a Spring Boot service:
boolean isEnabled = featureFlagService.isFeatureEnabled("darkMode");
if (isEnabled) {
return "Dark mode enabled";
} else {
return "Dark mode disabled";
}

If the feature flag "darkMode" is set to false, what will be the returned string?
A"Dark mode enabled"
BException thrown
Cnull
D"Dark mode disabled"
Step-by-Step Solution
Solution:
  1. Step 1: Check feature flag value

    The flag "darkMode" is false, so isEnabled is false.
  2. Step 2: Follow if-else logic

    Since isEnabled is false, the else block runs returning "Dark mode disabled".
  3. Final Answer:

    "Dark mode disabled" -> Option D
  4. Quick Check:

    Flag false means else block runs [OK]
Quick Trick: False flag triggers else block return [OK]
Common Mistakes:
  • Assuming true when flag is false
  • Expecting null or exception instead of else return

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes