What is the difference between Runnable and extends Thread

0 votes

There are 2 ways of writing Threads in Java:

public class myRunnable implements Runnable {
    public void run() {
        //Code
    }
}

Or, with extends Thread:

public class myThread extends Thread {
    public myThread() {
        super("myThread");
    }
    public void run() {
        //Code
    }
}

What are the significant differences in these two blocks of code?

Apr 30, 2018 in Java by developer_1
• 3,270 points

edited Apr 30, 2018 by developer_1 70 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
Runnable is the preferred way to create a thread as it. You're not really specialising the thread's behaviour. You're just giving it something to run.

It means you can implement Runnable and extend from another class as well. while extending thread we cannot extend another class.
answered Apr 30, 2018 by sharth
• 3,310 points

Related Questions In Java

0 votes
2 answers

What is the difference between implements and extends?

Extends : This is used to get attributes ...READ MORE

answered Aug 3, 2018 in Java by samarth295
• 2,190 points
374 views
0 votes
1 answer

What is the difference between jdk and jre?

JRE: It stands for Java Runtime Environment. ...READ MORE

answered Apr 20, 2018 in Java by Akrati
• 3,150 points
83 views
0 votes
2 answers

What is the difference between = and equals()?

The equals() method compares the "value" inside String instances ...READ MORE

answered Aug 13, 2018 in Java by Daisy
• 8,040 points
28 views
0 votes
1 answer

What is the difference between Set and List in java?

List is an ordered sequence of elements. ...READ MORE

answered Apr 26, 2018 in Java by Akrati
• 3,150 points
32 views
0 votes
1 answer

difference between wait() and sleep() in java

We can find a big difference between ...READ MORE

answered Apr 25, 2018 in Java by developer_1
• 3,270 points
49 views
0 votes
2 answers
0 votes
1 answer

How to retrieve current stack trace?

Yes, in Java we do have a ...READ MORE

answered May 16, 2018 in Java by code.reaper12
• 3,450 points
87 views
0 votes
1 answer

How to kill a thread in Java?

You can use a shared variable as ...READ MORE

answered Jun 6, 2018 in Java by Akrati
• 3,150 points
63 views
0 votes
1 answer

what are the ways in which a list can be iterated

  There are 5 ways to iterate over ...READ MORE

answered Apr 23, 2018 in Java by sharth
• 3,310 points
29 views
+1 vote
2 answers

What are inner classes and static nested classes?

Nested classes are divided into two categories: ...READ MORE

answered Dec 3, 2018 in Java by Sushmita
• 6,840 points
38 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.