Thanks a lot for the replies.
The source of the above code was a tutorial on threads that i found on W3schools:
*www.w3schools.com/java/java_threads.asp
This example can be found under the topic entitled "Concurrency problems"
I agree that using the runnable interface seems like a better idea,as extending the Thread class could prevent the class containing the code from extending other classes,if needed.
It seems the purpose of using threads is to allow the code/program to operate more efficiently by "doing multiple things at the same time"-i can't quite understand from the above example how this is being accomplished.Rather than using threads,one could simply achieve this by calling a function that's dedicated to that particular task(such as incrementing the value of amount in the above example)-so what added advantage does a thread bring to the table?
Can anyone please point me to a simple example that illustrates the above concept ie thread being used to do multiple things simultaneously in a more lucid manner?
Also how can i create and run multiple threads in the same program?I think in this example they have only created one thread that modifies the value of amount only one time.
Ever since i started learning java,the concept of threads has always kind of confounded me.Threads are supposed to make programming more efficient,but the examples i found online or in text books only increased my confusion rather than mitigating it.