In Java programming, which of the following should you use when you want to access the same resource from a group of threads?
- Volatile keyword
- Resource interface
- Extending thread class
- Runnable interface
EXPLANATION
There is no difference. It all depends on the need and requirements. Let me explain this to you with an example.Java doesn’t support multiple inheritance, which means you can only extend (inherit) one class so once you extend the Thread class you cannot extend or inherit another class in Java. As per object oriented programing(OOPs), the
whole purpose of inheritance is to add new functionality, modifying or improving behaviors by overriding methods of parent class. If we are not making any modification on Thread then using Runnable interface should be your choice instead of extending Thread class. There are few more things to discuss regarding this. I will cover them in detail in a separate post. I hope this makes sense now.
0 comments:
Post a Comment