Bird
0
0

Why is it recommended to declare the logger as private static final in Spring Boot classes?

hard📝 Conceptual Q10 of 15
Spring Boot - Logging
Why is it recommended to declare the logger as private static final in Spring Boot classes?
ATo allow each object instance to have its own logger
BTo enable logger to be changed at runtime
CTo ensure a single shared logger instance per class and prevent reassignment
DTo make logger accessible from other classes
Step-by-Step Solution
Solution:
  1. Step 1: Understand static modifier effect

    Static means one logger instance shared by all objects of the class.
  2. Step 2: Understand final modifier effect

    Final prevents reassignment, ensuring logger reference stays constant.
  3. Final Answer:

    To ensure a single shared logger instance per class and prevent reassignment -> Option C
  4. Quick Check:

    Logger modifiers purpose = To ensure a single shared logger instance per class and prevent reassignment [OK]
Quick Trick: Use private static final for one constant logger per class [OK]
Common Mistakes:
  • Thinking logger should be instance variable
  • Assuming logger can be reassigned
  • Believing logger should be public

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes