Saturday, 25 May 2013

Exception - 12 -

Select all  the exceptions thrown by wait() method of an Object class, which you can replace in the place of xxx legally? 

package net.dharmaraj;

class T implements Runnable
{
    public void run()
    {
        System.out.println("Executing run() method");
        myTest();
    }

    public synchronized void myTest() 
            { 
               try
               { 
                   wait(-1000);  
                   System.out.println( "Executing the myTest() method" ) ; 
               }   //XXX 
             
            }}

public class MyTest
{
    public static void main(String args[])
    {
        T t = new T();
        Thread th = new Thread(t);
        th.start();
    }
}



A) catch ( InterruptedException ie) {} 
B) catch ( IllegalArgumentException il ) {} 
C) catch ( IllegalMonitorStateException im ) {} 
D) Only catch ( InterruptedException e ) {} exception


Answer.-- a, b, c

No comments:

Post a Comment