Monday, 2 April 2012

MCQ- Exception handling


MCQ- Exception handling

1. The exception class is in ____ package
A. java.file

B. java.io
C. java.lang
D. java.util
2. Which keyword is used to monitor statement for exception?
A. try
B.ctach
C. throw
D. throws

3. If an exception  is generated in try block , then it is caught in ____ block
A. finally
B. throw
C. throws
D. catch

4. To explicitly throw an exception , ______ keyword is used.
A. try
B.ctach
C. throw
D. throwing

5. ______ is a superclass of all exception classes.
A. Exception
B. Throwable
C. RuntimeException
D. IOException

6. Exception is subclass of ____ class
A. Exception
B. Throwable
C. RuntimeException
D. IOException

7. If a statement tries to divide by zero which exception is thrown?
A.ArithemticException
B.NullPointerException
C.NumberFormatException
D. None of these

8. When a method can throw an exception then it is specified by _____ keyword
A. finally
B. throw
C. throws
D. catch

9. Which block gets executed compulsory whether exception is caught or not.
A. finally
B. throw
C. throws
D. catch

10. To create our own exception class , we have to _______
A. Extend exception class
B. Create our own try and catch block
C. use finally block
D. Use throws keyword
11. In case of multiple catch blocks,______
A. The superclass exception must be caught first
B. A. The superclass exception can not caught first
C. Either super or subclass can be caught first.
D. None of these

12. When an array element is accessed beyond the array size , ____ exception is thrown
A. ArrayElementOutOfLimit
B. ArrayIndexOutOfBounds Exception
C. ArrayIndexOutOfBounds
D. ArrayElementOutOfBounds

13. Which method is used to print the description of the exception?
A. printStackTrace()
A. printExceptionMessage()
A. printStackMessage()
A. printExceptionTrace()

14. What is the output of following try catch block
try
    int i;
    return;
 }
 catch(Exception e)
   {
       System.out.println(“Hello India”);
   }
finally
   {
       System.out.println(“Hello Morbi”);
   }
           
A. Hello India
B. Hello India
    Hello Morbi
C. Hello Morbi
D. the program will return without printing anything

15. Which of the following must be true of the object thrown by a throw statement?
A. It must be assignable to the Throwable type
B. It must be assignable to the Error type
C. It must be assignable to the Exception type
D. It must be assignable to the String type
     

Answers:

1
- C
2
- A
3
- D
4
- C
5
- B
6
- B
7
- A
8
- C
9
- A
10
- A
11
- B
12
- B
13
- A
14
- C
15
- A

Posted By :Ruchita Pandya

2 comments: