My Report (&Account)

Java Collections 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 program?

 
    class exception_handling 
    {
        public static void main(String args[]) 
        {
            try 
            {
                System.out.print("Hello" + " " + 1 / 0);
            }
            catch(ArithmeticException e) 
            {
        	System.out.print("World");        	
            }
        }
    }

2. When does Exceptions in Java arises in code sequence?

3. Which of these keywords is used to manually throw an exception?

4. Which of these keywords must be used to monitor for exceptions?

5. What will be the output of the following Java program?

 
    class exception_handling 
    {
        public static void main(String args[]) 
        {
            try 
           {
                int a, b;
                b = 0;
                a = 5 / b;
                System.out.print("A");
            }
            catch(ArithmeticException e) 
            {
        	System.out.print("B");        	
            }
        }
    }

6. Which of these keywords must be used to handle the exception thrown by try block in some rational manner?

7. What will be the output of the following Java program?

 
    class exception_handling 
    {
        public static void main(String args[]) 
        {
            try 
            {
                int i, sum;
                sum = 10;
                for (i = -1; i < 3 ;++i)
                    sum = (sum / i);
            }
            catch(ArithmeticException e) 
            {
        	System.out.print("0");        	
            } 
            System.out.print(sum);
        }
    }

8. Which of these keywords is not a part of exception handling?

9. What will be the output of the following Java program?

 
    class exception_handling 
    {
        public static void main(String args[]) 
        {
            try 
            {
                int a, b;
                b = 0;
                a = 5 / b;
                System.out.print("A");
            }
            catch(ArithmeticException e) 
            {
        	System.out.print("B");        	
            }
            finally 
            {
    	        System.out.print("C");
            }
        }
    }

 

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.