A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

Overloading of run() method

Overloading of run() method in thread

What will happen if we overload the run() method?

Overloading of run() method is always possible, but thread class start() method can invoked no-argument run() method.
The other overloaded method, we have to call explicitly like a normal method call.

Program for overloading run method

Class MyThread extends Thread

{
    Public void run()
    {
        System.out.println(no-arg run);
    }
    Public void run(int i)
    {
        System.out.println(int-arg run);
    }
}
Class Test
{
    Public static void main(String[]args)
    {
        MyThread t =new MyThread();
        t.start();
    }
}

output:




If we are not overriding run () method, then Thread class run() method will be executed. Which has empty implementation. Hence we won’t get any output.


Output:


no output

Note:

It is highly recommended to override run() method otherwise don’t go for multithreading concept.













LEARN TUTORIALS

.

.