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 is the priority of the thread in the following Java Program?

 
    class multithreaded_programing 
    {
        public static void main(String args[])
        {
            Thread t = Thread.currentThread();
            System.out.println(t);        
        }
    }

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

 
    import java.util.*;
    class Collection_Algos 
    {
        public static void main(String args[]) 
        {
            LinkedList list = new LinkedList();
            list.add(new Integer(2));
            list.add(new Integer(8));
            list.add(new Integer(5));
            list.add(new Integer(1));
            Iterator i = list.iterator();
            Collections.reverse(list);
	    while(i.hasNext())
	        System.out.print(i.next() + " ");
        }
    }

3. Which of these method is used to tell the calling thread to give up a monitor and go to sleep until some other thread enters the same monitor?

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

 
    import java.util.*;
    class Collection_Algos 
    {
        public static void main(String args[]) 
        {
            LinkedList list = new LinkedList();
            list.add(new Integer(2));
            list.add(new Integer(8));
            list.add(new Integer(5));
            list.add(new Integer(1));
            Iterator i = list.iterator();
            Collections.reverse(list);
	    Collections.sort(list);
            while(i.hasNext())
	        System.out.print(i.next() + " ");
        }
    }

5. 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(Myexception e)
           {
               System.out.print("Exception");
           } 
        }
    }

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

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

8. Which of these handles the exception when no catch is used?

9. What requires less resources?

10. 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();
	}
	public void run()
        {
	    System.out.println(t);
	}
    }
    class multithreaded_programing
    {
        public static void main(String args[])
        {
            new newthread();        
        }
    }

 

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.