/*This question from the herbert schildth book gives 10 error when compiled
Is there anything that is going wrong.*/
class CurrentThreadDemo extends Thread{
public static void main(
String args[]) {
Thread t = Thread.currentThread();
System.out.println("Current thread: " + t);
// change the name of the thread
t.setName("My Thread");
System.out.println("After name change: " + t);
try {
for(int n = 5; n > 0; n--) {
System.out.println(n);
Thread.sleep(1000);
}
} catch (InterruptedException e) {
System.out.println("Main thread interrupted");
}
}
}
/**
D:\MyJava\MyProg\Chap7@Threads@\CurrentThreadDemo.java:2: cannot resolve symbol
symbol : constructor Thread ()
location: class Thread
class CurrentThreadDemo extends Thread{
^
D:\MyJava\MyProg\Chap7@Threads@\CurrentThreadDemo.java:4: cannot resolve symbol
symbol : method currentThread ()
location: class Thread
Thread t = Thread.currentThread();
^
D:\MyJava\MyProg\Chap7@Threads@\CurrentThreadDemo.java:6: operator + cannot be applied to java.lang.String,Thread
System.out.println("Current thread: " + t);
^
D:\MyJava\MyProg\Chap7@Threads@\CurrentThreadDemo.java:9: cannot resolve symbol
symbol : method setName (java.lang.String)
location: class Thread
t.setName("My Thread");
^
D:\MyJava\MyProg\Chap7@Threads@\CurrentThreadDemo.java:10: operator + cannot be applied to java.lang.String,Thread
System.out.println("After name change: " + t);
^
D:\MyJava\MyProg\Chap7@Threads@\CurrentThreadDemo.java:15: cannot resolve symbol
symbol : method sleep (int)
location: class Thread
Thread.sleep(1000);
^
.\Thread.java:1: cannot resolve symbol
symbol : constructor Thread ()
location: class Thread
class A extends Thread {
^
.\Thread.java:3: incompatible types
found : A
required: java.lang.Object
synchronized (this) {
^
.\Thread.java:4: cannot resolve symbol
symbol : method wait ()
location: class A
try{wait();} catch (InterruptedException ie){}
^
.\Thread.java:10: cannot resolve symbol
symbol : method start ()
location: class A
a1.start();
^
10 errors
Tool completed with exit code 1
**/