• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Marcus Exam

 
Thiru Thangavelu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this answer explanation is correct in marcus exam 2? He didn't mention why b.run() doesn't cause the error? I guess since the Thread method has run() method which will be called when there is no explicit run() in your class. Is this correct?
public class Bground extends Thread{
public static void main(String argv[]){
Bground b = new Bground();
b.run();
}
public void start(){
for (int i = 0; i <10; i++){
System.out.println("Value of i = " + i);
}
}
}
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Thiru Thangavelu:
Is this correct?

Yes. The class Thread implements the Runnable interface so it is required to have a run method. Of course, the run method, as defined in Thread, does nothing. However, as Thread has a run method, it is legal to invoke it.
Corey
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic