Assertions Questions and Answers
Practice ModeShowing 10 of 45 questions
Q41
How to enable assertions for a specific class only?
Answer: Option A
Explanation: The -ea:ClassName syntax enables assertions for specific classes.
Q42
What will happen if you use assertions in Java 1.3 without compatibility mode?
Answer: Option B
Explanation: assert was not a keyword before Java 1.4, so it would cause compilation errors.
Q43
Which of these correctly checks if a list is not null and not empty using assertion?
Answer: Option A
Explanation: The condition should verify both not null and not empty states.
Q44
What is the main advantage of using assertions over System.out.println for debugging?
Answer: Option C
Explanation: Assertions can be easily disabled in production without removing code.
Q45
Which Java version first introduced assertions?
Answer: Option C
Explanation: Assertions were officially added in Java 1.4 release.