class Sample extends Thread { Sample() { super(); start(); } public void run() { for(int i=0;i<3;i++) { try { System.out.println(Thread.currentThread().getName()+" - "+i); Thread.sleep(1000); } catch(InterruptedException e) { System.out.println("hii"); } } } } class Main { public static void main(String[] args) { Sample t1=new Sample(); for(int i=0;i<3;i++) { try { System.out.println(Thread.currentThread().getName()+" - "+i); Thread.sleep(1000); } catch(InterruptedException e) { System.out.println("hello"); } } } }