Whenever we override start() method then our start() method will be executed just like a normal method call and new thread wont be created. We can override start/run method of Thread class because it is not final. But it is not recommended to override start() method, otherwise it ruins multi-threading concept.
Start Method Main Method
NOTE : In the above program, when we are calling start() method by an object of Bishal class, then any thread won’t be created and all the functions are done by main thread only.
Runtime stack provided by JVM for the above program:
When we call start() method on thread, it internally calls run() method with newly created thread. So, if we override start() method, run() method will not be called until we write code for calling run() method.
GThread: start() GRunnable: run()
When GThread.start() is called, output is : “GThread:start()”. When we call, thread.start(), the new thread will call the run() method of runnable, and we will get the “GRunnable:run()” message.
This article is contributed by Bishal Kumar Dubey. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Difference between Thread.start() and Thread.run() in Java
- Naming a thread and fetching name of current thread in Java
- How a thread can interrupt an another thread in Java?
- Difference between Method Overloading and Method Overriding in Java
- Overloading of Thread class run() method
- Overriding equals method in Java
- Exception Handling with Method Overriding in Java
- Method Overriding with Access Modifier
- Java.lang.Thread class in Java
- isAlive() and join() methods of Thread Class in Java
- Overriding toString() in Java
- Overriding in Java
- Overriding methods from different packages in Java
- Matcher start() method in Java with Examples
- Matcher start(int) method in Java with Examples
- Matcher start(String) method in Java with Examples
- MatchResult start() method in Java with Examples
- MatchResult start(int) method in Java with Examples
- Inter-thread Communication in Java
- Daemon thread in Java