Posts

Showing posts with the label Extend




Extend Thread or Runnable Which Is Best Practice

Image
In the first approach Our class always extends Thread class. Its usually a better idea to implement Runnable. Heavyweight And Lightweight Threads We Know Earlier The Meaning Of Heavyweight And Lightweight Threads Now Let Us See How To Thread Lightweight Meant To Be Hence we are missing Inheritance benefits. . When extending the Thread class were not overriding any of its methods. Extending Thread VS implementing Runnable. Java does not allow multiple inheritance so if you extend from thread you can not extend from any other class. Both approaches have their pros and cons and there is a situation when extending Thread is logical but in most cases implementing Runnable is the better option. Best Object Oriented Design Practice. In an interview I have been asked a questiongive one situation where you will prefer to create a thread using extending a thread class over implementing Runnable interface. A user mus...