Java - Exceptions - Interview Questions and Answers on RuntimeException

Q1.  What are the sub classes of Exception class?

Ans. The Exception class has two main subclasses : IOException class and RuntimeException Class.

Q2.  What things should be kept in mind while creating your own exceptions in Java?

Ans. All exceptions must be a child of Throwable.

If you want to write a checked exception that is automatically enforced by the Handle or Declare Rule, you need to extend the Exception class.

You want to write a runtime exception, you need to extend the RuntimeException class.

Q11. Which are the subclasses for RuntimeException?

Ans.[, ConcurrentModificationException, ProviderException, MissingResourceException, UnknownEntityException, UncheckedIOException, EmptyStackException, ArithmeticException, DateTimeException, UndeclaredThrowableException, CannotUndoException, FileSystemAlreadyExistsException, IncompleteAnnotationException, BufferUnderflowException, EnumConstantNotPresentException, IllegalArgumentException, UnsupportedOperationException, IndexOutOfBoundsException, TypeConstraintException, CannotRedoException, ProfileDataException, IllformedLocaleException, NoSuchMechanismException, NegativeArraySizeException, FileSystemNotFoundException, ImagingOpException, DataBindingException, ArrayStoreException, IllegalStateException, MirroredTypesException, IllegalPathStateException, AnnotationTypeMismatchException, CMMException, DOMException, ProviderNotFoundException, SystemException, NullPointerException, BufferOverflowException, MalformedParametersException, JMRuntimeException, MalformedParameterizedTypeException, TypeNotPresentException, WebServiceException, EventException, SecurityException, RejectedExecutionException, UnmodifiableSetException, ClassCastException, CompletionException, WrongMethodTypeException, IllegalMonitorStateException, LSException, NoSuchElementException, RasterFormatException]

Q13. Which is the Parent Class of IllegalStateException class?

Ans.java.lang.RuntimeException