class ThDemo extends Thread { public void run() { int x; try { for(x=1;x<=10;x++) { Thread.sleep(2000); System.out.println("Hello Sateesh"); } } catch(Exception e) { System.out.println(e); } } } public class Main { public static void main(String args[]) { ThDemo1 d=new ThDemo1(); d.start(); System.out.println("Thread Name is "+d.getName()); } }
Thread Name is Thread-0
Hello Sateesh
Hello Sateesh
Hello Sateesh
Hello Sateesh
Hello Sateesh
Hello Sateesh
Hello Sateesh
Hello Sateesh
Hello Sateesh
Hello Sateesh