Bird
0
0

Identify the error in this custom exception class:

medium📝 Debug Q6 of 15
Java - Custom Exceptions
Identify the error in this custom exception class:
public class MyException extends Exception {
  public MyException(String message) {
    super();
  }
}
Asuper() should be super(message)
BConstructor should be private
CClass must extend RuntimeException
DNo error, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Review constructor calling superclass

    The constructor takes a message but calls super() without passing it.
  2. Step 2: Understand Exception constructor usage

    To pass the message to Exception, super(message) must be called.
  3. Final Answer:

    super() should be super(message) -> Option A
  4. Quick Check:

    Pass message to superclass constructor with super(message) [OK]
Quick Trick: Pass message to Exception with super(message) in constructor [OK]
Common Mistakes:
  • Calling super() without message in parameterized constructor
  • Making constructor private unnecessarily
  • Extending wrong exception class

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes