Object Oriented Programming - I (3140705) MCQs

MCQs of Exception Handling, I/O, abstract classes and interfaces

Showing 11 to 20 out of 38 Questions
11.
Which part of code gets executed whether exception is caught or not?
(a) finally
(b) try
(c) catch
(d) throw
Answer:

Option (a)

12.
Which of the following should be true of the object thrown by a thrown statement?
(a) Should be assignable to String type
(b) Should be assignable to Exception type
(c) Should be assignable to Throwable type
(d) Should be assignable to Error type
Answer:

Option (c)

13.
At runtime, error is recoverable.
(a) TRUE
(b) FALSE
Answer:

Option (b)

14.
Which of these class is related to all the exceptions that can be caught by using catch?
(a) Error
(b) Exception
(c) RuntimeExecption
(d) All of the mentioned
Answer:

Option (b)

15.
What exception thrown by parseInt() method?
(a) ArithmeticException
(b) ClassNotFoundException
(c) NullPointerException
(d) NumberFormatException
Answer:

Option (d)

16.
What will be the output of the following Java code?
    class exception_handling 
    {
        public static void main(String args[]) 
        {
            try 
            {
                int a = args.length;
                int b = 10 / a;
                System.out.print(a);
                try 
                {
                    if (a == 1)
                        a = a / a - a;
                    if (a == 2) 
                    {
                        int []c = {1};
                        c[8] = 9;
                    }
                }
                catch (ArrayIndexOutOfBoundException e) 
                {
                    System.out.println("TypeA");
                }
                catch (ArithmeticException e) 
                {
                    System.out.println("TypeB");
                }
            }
        }
    }
(a) TypeA
(b) TypeB
(c) Compile Time Error
(d) 0TypeB
Answer:

Option (c)

17.
What will be the output of the following Java code?
    class exception_handling 
    {
        public static void main(String args[]) 
        {
            try 
            {
                System.out.print("A");
                throw new NullPointerException ("Hello");
            }
            catch(ArithmeticException e) 
            {
                System.out.print("B");        	
            }
        }
    }
(a) A
(b) B
(c) Hello
(d) Runtime Exception
Answer:

Option (d)

18.
A single try block must be followed by which of these?
(a) finally
(b) catch
(c) finally & catch
(d) none of the mentioned
Answer:

Option (c)

19.
Which of these exceptions will occur if we try to access the index of an array beyond its length?
(a) ArithmeticException
(b) ArrayException
(c) ArrayIndexException
(d) ArrayIndexOutOfBoundsException
Answer:

Option (d)

20.
What is the use of try & catch?
(a) It allows us to manually handle the exception
(b) It allows to fix errors
(c) It prevents automatic terminating of the program in cases when an exception occurs
(d) All of the mentioned
Answer:

Option (d)

Showing 11 to 20 out of 38 Questions