Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6896345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:01:40+00:00 2026-05-27T07:01:40+00:00

Possible Duplicate: java thread – run() and start() methods I made a program which

  • 0

Possible Duplicate:
java thread – run() and start() methods

I made a program which uses threading—

public class ThreadTest{    
    public static void main(String[] args){     
        MyThread newthread=new MyThread();
        Thread t=new Thread(newthread);
        t.start();
        for(int x=0;x<10; x++){
            System.out.println("Main"+x)
        }
    }
} 

class MyThread implements Runnable{
    public void run(){
        for(int x=0; x<10; x++){
            System.out.println("Thread"+x);
        }
    }
}

Now my question is that … why do we use the “Thread” class and create it’s object and pass the “MyThread” calls in it’s constructor? can’t we call the run method of the “MyThread” object by creating it’s object and calling the run method?

( i.e MyThread newthread=new MyThread(); and then newthread.run(); )

What’s the reason for creating tread objects and passing the MyThread class in it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:01:40+00:00Added an answer on May 27, 2026 at 7:01 am

    The MyThread class is not a thread. It is an ordinary class that implements Runnable and has a method called run.

    If you call the run method directly it will run the code on the current thread, not on a new thread.


    To start a new thread you create a new instead of the Thread class, give it an object that implements Runnable, and then call the start method on the thread object. When the thread starts, it will call the run method on your object for you.

    Another way to start a thread is to subclass Thread and override its run method. Again to start it you must instantiate it and call the start method, not the run method.The reason is the same: if you call run directly it will run the method in the current thread.

    See Defining and Starting a Thread for more information about starting new threads in Java.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Java inner class and static nested class What are the uses of
Possible Duplicate: Thread safety in Java class I'm reading Java concurrency in Practice ,
Possible Duplicate: How can I convert my java program to an .exe file ?
Possible Duplicate: How do you find all subclasses of a given class in Java?
Possible duplicate: why-is-java-lang-throwable-a-class Hi! I doesn't understand why Throwable isn't abstract class. I see
Possible Duplicate: Exception in thread “main” java.lang.NoSuchMethodError: main My main syntax is correct. What
Possible Duplicate: Java Full Screen Program (Swing) -Tab/ALT F4 I've got a full screen
Possible Duplicate: Causes of 'java.lang.NoSuchMethodError: main Exception in thread “main”' i got this error
Possible Duplicate: Java: Start Mail-Client with Attachment? I need to create a java code
Possible Duplicate: Java - Creating an array of methods In java can i store

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.