My Report (&Account)

Java Exception Handling Test – 3


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. 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");        	
            }
        }
    }

2. Which of these keywords is used to by the calling function to guard against the exception that is thrown by called function?

3. Which of these operator is used to generate an instance of an exception than can be thrown by using throw?

4. Which of these keywords is used to generate an exception explicitly?

5. 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");
                }
            }
        }
    }

6. What will be the output of the following Java code?

 
public class San 
{
    public static void main(String args[])
    {
        try 
        {
            System.out.print("Hello world ");
        }
        finally 
        {
            System.out.println("Finally executing ");
        }
    }
}

7. Which of these class is related to all the exceptions that are explicitly thrown?

8. What will be the output of the following Java code?

 
public class San 
 {  
    public static void main(String[] args) 
    {
        try 
        { 
            return; 
        } 
        finally 
        {
            System.out.println( "Finally" ); 
        } 
    } 
}

 

Start practicing “1000 MCQs on Java”, and once you are ready, you can take tests on all topics by attempting our “Java Test Series”.

advertisement
advertisement
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.