method in java

Thread class contain a run() method which has empty implementation. So if we are using multithreading then we must override run() from Thread class.
If we override a in out class then the child thread is responsible to
execute this method.
If we don’t override a method in our class then it will call run() method from Thread class, which has no implementation. So no utput will get.

run() method won’t create a new Thread.

Overloading run() method

We can overload a method in our class. But Thread.start() always call no-argument run() method only. So if you want to call overloaded argument method, you have to call it explicitly.


Overriding run() method

We must override a run() method if we want to use multi-threading. If we don’t override a run(), then start() call which has empty implementation. so will not get any output.

Output:No output

Help others by sharing the content!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.