My Report

Java Programming Practice Test 7


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 
            {
                throw new NullPointerException ("Hello");
                System.out.print("A");
            }
            catch(ArithmeticException e) 
            {
        	System.out.print("B");        	
            }
        }
    }

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

    class Myexception extends Exception 
    {
	int detail;
        Myexception(int a)
        {
        detail = a;
	}
	public String toString()
        {
	    return "detail";
	}
    }
    class Output
    {
        static void compute (int a) throws Myexception
        {
	     throw new Myexception(a);	 
	}
	public static void main(String args[])
        {
            try 
            {
                compute(3);
            }
           catch(Exception e)
           {
               System.out.print("Exception");
           } 
        }
    }

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

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

 
    class newthread implements Runnable
    {
	Thread t;
	newthread()
        {
	    t = new Thread(this,"My Thread");
	    t.start();
	}
    }
    class multithreaded_programing
    {
        public static void main(String args[])
        {
            new newthread();        
        }
    }

5. What is multithreaded programming?

6. Which of the following is a correct constructor for thread?

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

    class Output 
    {
        public static void main(String args[]) 
        {
           try
           {
               int a = 0;
               int b = 5;
               int c = b / a;
               System.out.print("Hello");
           }
           catch(Exception e) 
           {
               System.out.print("World");
           } 
           finally 
           {
               System.out.print("World");
           } 
        }
    }

8. Which of these keywords are used for generating an exception manually?

9. Which of these method is used to explicitly set the priority of a thread?

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

 

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.