Mcq On Java Exception
31. What is the output of this program?
Explanation: Because finally will execute always.
32. A single try block must be followed by which of these?
Explanation: try block can be followed by any of finally or catch block, try block checks for exceptions and work is performed by finally and catch block as per the exception.
B is wrong. A try statement executes a block. If a value is thrown and the try statement has one or more catch clauses that can catch it, then control will be transferred to the first such catch clause. If that catch block completes normally, then the try statement completes normally.
C is wrong. Exceptions of type Error and RuntimeException do not have to be caught, only checked exceptions (java.lang.Exception) have to be caught. However, speaking of Exceptions, Exceptions do not have to be handled in the same method as the throw statement. They can be passed to another method.
33.Which of these exceptions handles the divide by zero error?
34.Which of these exceptions will occur if we try to access the index of an array beyond its length?
Explanation: ArrayIndexOutOfBoundsException is a built in exception that is caused when we try to access an index location which is beyond the length of an array.
35. What is the output of this program?
$ javac exception_handling.java
$ java exception_handling
Also check :