Bird
0
0

Which of the following is the correct syntax to declare a simple custom exception class named InvalidInputException?

easy📝 Syntax Q3 of 15
Spring Boot - Exception Handling
Which of the following is the correct syntax to declare a simple custom exception class named InvalidInputException?
Apublic InvalidInputException extends Exception {}
Bpublic class InvalidInputException extends RuntimeException {}
Cclass InvalidInputException implements RuntimeException {}
Dpublic class InvalidInputException extends Error {}
Step-by-Step Solution
Solution:
  1. Step 1: Check class declaration syntax

    Custom exceptions are classes extending a superclass, using 'extends' keyword.
  2. Step 2: Validate correct superclass and syntax

    RuntimeException is correct superclass for unchecked exceptions; class must be public if used widely.
  3. Final Answer:

    public class InvalidInputException extends RuntimeException {} -> Option B
  4. Quick Check:

    Correct class declaration extends RuntimeException [OK]
Quick Trick: Use 'extends RuntimeException' to declare unchecked custom exceptions [OK]
Common Mistakes:
  • Using 'implements' instead of 'extends'
  • Missing 'public' keyword when needed
  • Extending Error instead of RuntimeException

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes