Basics of Exception Handling in Java
This quiz has basics of Exception Handling questions
Questions
What would be the output of the following program?
Class A {
public static void main(String args[]) {
int a = 0;
int b = 10 / a;
}
}
- 0
- 10
- Infinite
- RuntimeException
- Compile Time Exception
Which of the following statements is false regarding 'finally' keyword in Java?
- Finally block does not get executed in case an exception does not occur.
- There can be multiple finally blocks in a Java method.
- Finally block is optional.
- A try statement without a catch block must be followed by a finally block.
- The finally block executes even if no catch block executes.
Which of the following is not an unchecked exception?
- ArithmeticException
- NullPointerException
- NumberFormatException
- ArrayIndexOutOfBoundsException
- IOException
Which of the following keywords is not associated with Java exception handling?
- try
- catch
- throw
- finally
- final
Which of the following is responsible for the occurence of exceptions?
- Syntactical errors
- Symentical errors
- Lexical errors
- Pass 1 error of the compiler
- Program load time error
Which of the following Exception classes in Java is used to deal with an exception, where an assignment to an array element is of incompatible type?
- ArithmeticException
- ArrayIndexOutOfBoundsException
- IllegalArgumentException
- ArrayStoreException
- IllegalStateException
Which of the following methods is used in Java to throw an exception explicitly in a program?
- Throws
- Throw
- Finally
- None of these
Which of the following Exception classes is used to deal with an exception of an attempt to violate the security?
- NullPointerException
- ClassNotFoundException
- IllegalAccessException
- InterruptedException
- SecurityException
Which of the following blocks in Java is executed regardless of whether an exception is thrown or not?
- try block
- catch block
- finally block
- final
- private
Which of the following methods of Throwable class sends the stack trace to the specified stream?
- printStackTrace()
- fillInStackTrace()
- printStackTrace(PrintStream stream)
- toString()
- getLocalizedMessage()
Name the exception thrown by read method of the InputStream class
- IOException
- ReadException
- FileNotFoundException
- Exception
- All of the above
Which of the following is not a Java's checked exception?
- ClassNotFoundException
- ClassNotSupportedException
- InstantiationException
- UnsupportedOperationException
- NoSuchMethodException
Which of the following classes is at the top of Exception class hierarchy?
- Exception
- Error
- Throwable
- RuntimeException
- IOException
Which of the following Exception classes is used when a requested operation is not compatible with the current thread state?
- ArithmeticException
- IllegalStateException
- IllegalThreadStateException
- ArrayStoreException
- NegativeArraySizeException