All of Marcus' mock exams are great and his website is very helpful, I need some clarification on question#31 in his exam#1...all of the cert books and tutorials (including his own Last Minute Tutorial) teach you to call the start method in order to call the run method of a
thread. The answer to Question 31 is...#3...Are there questions similar to this on the cert
test that do not comply with the main stream teachings but are considered legitimate? Any tips on how to prep for this type of question? ------------------------------------------------
Exam 1, Question 31.
What will happen when you attempt to compile and run the following code?
public class Holt extends Thread{
private
String sThreadName;
public static void main(String argv[]){
Holt h = new Holt();
h.go();
}
Holt(){}
Holt(String s){
sThreadName = s;
}
public String getThreadName(){
return sThreadName;
}
public void go(){
Holt first = new Holt("first");
first.start();
Holt second = new Holt("second");
second.start();
}
public void start(){
for(int i = 0; i < 2; i ++){
System.out.println(getThreadName() +i);
try{
Thread.sleep(100);
} catch(InterruptedException e){System.out.println(e.getMessage());}
}
}
}
1) Compile time error
2) Output of first0, second0, first0, second1
3) Output of first0, first1, second0, second1
4) Runtime error