Well, the reason why in your last example the runnable threads are operating on the same object is because you only have instantiated one object, but you're using it in both threads:
That's absolutely right. Thank you for your observation.
The point I wanted to prove here was that we can't create threads extending the Thread class that operates on the same object. And, that's the advantage of using the Runnable interface over the Thread class.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Well, the reason why in your last example the runnable threads are operating on the same object is because you only have instantiated one object, but you're using it in both threads:
If you want independent objects in your threads you can do that with runnable as well:
That's absolutely right. Thank you for your observation.
The point I wanted to prove here was that we can't create threads extending the Thread class that operates on the same object. And, that's the advantage of using the
Runnable
interface over theThread
class.