Core Java - Interview Questions and Answers for 'Runnable interface' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Core Java - Interview Questions and Answers for 'Runnable interface' - 3 question(s) found - Order By Rating

 Q1. Why do we use Thread Class as well as Runnable Interface for creating threads in Java ?Core Java
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Threads  Thread class  runnable interface


Related Questions

  Which keyword is used to provide explicit access of a code block to single thread ?

a. Transient
b. Final
c. Explicit
d. Synchronized
  Explain multithreading in Java ?
  What is a Deadlock ?
  Explain Thread States ?
  Why do we need Thread class even in case we execute thread using runnable interface ?
  What is the difference between time slicing and preemptive scheduling ?
  Difference between Process and Thread ?
  What is race condition ?
  What is the use of runnable interface if we can always create a new thread using Thread class ?
  What is an object's lock and which object's have locks?


 Q2. What is the use of runnable interface if we can always create a new thread using Thread class ?Core Java
Ans. It's a choice to be made whether to use first approach ( Thread class ) or second approach ( runnable interface ) by the programmer. The second facility has been given for cases where your class is already extending some parent class and hence cannot extend another class ( for Thread ) as Java doesn't allow multiple inheritance.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   threads   multithreading   runnable interface  concurrency


Related Questions

  Why do we need Thread class even in case we execute thread using runnable interface ?
 Why do we use Thread Class as well as Runnable Interface for creating threads in Java ?
 What is the there only one method declared in Runnable interface?
 How executor service is better than using primitive Threading mechanism using Thread class or runnable Interface ?


 Q3. Why do we need Thread class even in case we execute thread using runnable interface ?Core Java
Ans. Thread class holds the definition of start method ( This is the method that starts execution of new thread and then calls run method within the scope of new thread ). Interfaces don't hold any definition and so does runnable. So it makes it necessary the usage of Thread class , whatever implementation you choose.

When your class extends the thread class, it carries the definition of start method from parent Thread class onto itself and hence new yourClass.start() helps starting a new thread and then executing run method in that new thread scope.

When you implement runnable interface , you are just making it sure to the JVM that you have implemented the required method ( run() ) which the Thread start method will look for upon executing start method.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   threads   multithreading   runnable interface   thread class


Related Questions

  What is the use of runnable interface if we can always create a new thread using Thread class ?
 Why do we use Thread Class as well as Runnable Interface for creating threads in Java ?
 What is the there only one method declared in Runnable interface?
 How executor service is better than using primitive Threading mechanism using Thread class or runnable Interface ?



Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: