SCJP Certification

Sun Certified Java Programmer Certification exam essentials

August 31st, 2009

What will happen if a user tries to overload the run() method?

Java Facts, by Daisy Williams.

run() is a method of the Thread class and the Runnable interface. It makes up the entire body of a thread. It is the only method in which a thread’s behavior can be implemented. The return type of the run() method must be void. In Java, it is quite easy to overload the run() method. However, the overloaded run() method will be ignored by the Thread class unless it is called by the programmer. The Thread class expects a run() method without any argument and will execute the overloaded method when the programmer calls the method by a separate call. For example:

class MyThreadDemo extends Thread
{
public void run()
{
System.out.println(“job running”);
}
public void run(String str)
{
System.out.println(“The running string is:” +str);
}
}

Share

Back Top

Responses to “What will happen if a user tries to overload the run() method?”

Comments (0) Trackbacks (0) Leave a comment Trackback url
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Your email address will not be published. Required fields are marked *

*