IT Questions and Answers :)

animated-update-image-0026

COVID-19 India HEAT MAP

A message to our readers about COVID-19

With the uncertainty surrounding the outbreak of the corona virus. We want to reassure our reader stay safe and Healthy.Be aware and alert. Work as one nation. Sanitize and disinfect all equipment before entering your home, work and anywhere.

Wednesday, July 10, 2019

In Java programming, which of the following should you use when you want to access the same resource from a group of threads?

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
In Java programming, which of the following should you use when you want to access the same resource from a group of threads?

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.
Share:

0 comments:

Post a Comment

Popular Posts