The code snippet given below is taken from
Marcus Green's Mock Exam 1 It was the healthy exam
But the answer(output) for this question is 4 out of following oprions
1) It will cause a compile time error
2) Compilation and output of "waiting"
3) Compilation and output of "waiting" followed by "finished"
4) Runtime error, an exception will be thrown
My answer is 1 as code below contains "while(true)".
Please guide am I right or wrong?
<code>
public class Agg{public static void main(
String argv[]){
Agg a = new Agg();
a.go();
}
public void go(){
DSRoss ds1 = new DSRoss("one");
ds1.start();
}
}
class DSRoss extends Thread{
private String sTname="";
DSRoss(String s){
sTname = s;
}
public void run(){
notwait();
System.out.println("finished");
}
public void notwait(){
while(true){
try{
System.out.println("waiting");
wait();
}catch(InterruptedException ie){}
System.out.println(sTname);
notifyAll();
}
}
}
</code>