Input
Output
class InterDemo extends Thread{ public void run(){ try{ Thread.sleep(1000); System.out.println("task"); }catch(InterruptedException e){ System.out.println(e); } } public static void main(String args[]){ InterDemo t1=new InterDemo(); t1.start(); try{ t1.interrupt(); }catch(Exception e){ System.out.println("Exception handled "+e); } } }