we haven't started the thread anywhere through which our run() method will run(i.e "new Thread(horse.get(index)).start()"). Then how we will reach the code inside the run() method. Help out please!!
passed the task...but i am bit confused.
Under discussion
Comments (6)
- Popular
- New
- Old
You must be signed in to leave a comment
BlueJavaBanana
25 September 2020, 17:09
Did your code not have this in it?
+1
sourav bamotra
25 September 2020, 17:21
ohhh yess....damn how didn't i see that lol. seems like i need a kit kat break.
0
sourav bamotra
25 September 2020, 17:28
but as per i have learned yet. we first create a Thread Object and pass the class object as argument to it and then start the thread.
0
sourav bamotra
25 September 2020, 17:42
ok wait....since our Horse class extends the Thread class...so there's no problem with the start method. but for what purpose start() method is implemented for.
0
BlueJavaBanana
25 September 2020, 18:04
When you call the start(); method on an object that extends Thread or implements the Runnable interface you tell the JVM to create a new thread and start running from the objects run() method.
But if you simply call the run(); method then your existing main thread simply executes the code in the run method, no new thread is created.
+2
sourav bamotra
25 September 2020, 19:37
well! thank you Banana I'll keep that in mind :)
0