extending thread class or implementing runnable interface. Which is better? : Java thread
Answer / Ujjwal Kumar
Both extending the Thread class and implementing the Runnable interface are ways to create a new thread in Java, but they have some differences. Extending the Thread class makes your class a subclass of the Thread class automatically with access to its instance methods like start(), run(), sleep() etc. However, it can lead to code duplication if you want to create multiple threads having common functionality. On the other hand, implementing the Runnable interface allows for better reusability and encapsulation as you define your thread's behavior in the run() method and then pass that Runnable object to a new Thread instance. So, it is generally considered better to implement the Runnable interface when creating threads.
| Is This Answer Correct ? | 0 Yes | 0 No |
Name four container classes.
Is call by reference possible in java?
what is the constructor and how many types of constructors are used in java?
What are meta-annotations?
What are the advantages and disadvantages of reference counting in garbage collection?
Difference between a process and a program?
What are access specifiers in java ?
1 Answers Akamai Technologies,
why java does not support unsigned keyword?
how cani read a command line argument?(usingfile object).
How do you check if an arraylist is not empty?
How to define a constant variable in Java?
Mention a package that is used for linked list class in java.