
why following code gives compile time error.please reply.
class ThreadDemo1 extends Thread { public void run() { for(int i=1;i<=3;i++) { System.out.println(i); try { Thread.sleep(1000); } catch(InterruptException e) { System.out.println(e); } } } public static void main(String[]arg) { ThreadDemo1 t1=new ThreadDemo1(); t1.start(); } }

class ThreadDemo1 extends Thread {
public void run() {
for(int i=1;i<=3;i++) {
System.out.println(i);
try {
Thread.sleep(1000);
}
catch(Exception e) {
System.out.println(e);
}
}
}
public static void main(String[]arg) {
ThreadDemo1 t1=new ThreadDemo1();
t1.start();
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.