← Back to libraryQuestion 43 of 273
JavaIntermediate

Annotations

📖 Detailed Explanation:

Annotations provide metadata about code that is NOT part of the code itself. They can be processed by the compiler (e.g., @Override), used at runtime via reflection (e.g., @Test), or both. Retention policies: SOURCE (discarded by compiler), CLASS (in .class file but not loaded at runtime), RUNTIME (available for reflection).

🌍 Real-World Example:

Annotations: Sheet music notes that don't change the notes but provide instructions (forte, slow). @Override: Tells compiler to check that the parent method exists.

🎯 Scenario-Based Interview Question:

How does @Override annotation help prevent bugs? Provide examples of bugs it catches.