problem with multithreading
i tried the following code
package pack;
class newthread extends Thread {
super("Demo Thread");
System.out.println("Child Thread: " + this);
start ( );
}
public void run( ) {
try {
for(int i=5; i>0; i--) {
System.out.println("Child thread " + i );
Thread.sleep(500)
}catch(InterruptedException e) {
System.out.println("child interrupted");
}
System.out.println("Exiting Child Thread");
}
}
class extendthread {
public static void main(String arg[]) {
new newthread();
try {
for(int i=5; i>0; i--) {
System.out.println("Main thread " + i );
Thread.sleep(1000);
}
}
catch(InterruptedException e) {
System.out.println("Main interrupted");
}
System.out.println("Exitin Main Thread");
}
}
and got following errors :---->
i:\JavaPrograms\pack\extendthread.java:4: illegal start of type
super("Demo Thread");
^
i:\JavaPrograms\pack\extendthread.java:4: <identifier> expected
super("Demo Thread");
^
i:\JavaPrograms\pack\extendthread.java:5: <identifier> expected
System.out.println("Child Thread: " + this);
^
i:\JavaPrograms\pack\extendthread.java:6: invalid method declaration;
return type required
start ( );
^
i:\JavaPrograms\pack\extendthread.java:9: 'class' or 'interface'
expected
public void run( ) {
^
i m using Java2 version 1.4 . i couldn't figure out why any of these
errors appeared
as of why did the compiler show error in line <
System.out.println("Child Thread: " + this); >
please elaborate why these errors appeared and of way/s to remove them
gonna be greateful
thanks