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,350 points

edited Apr 30, 2018 by developer_1 1,154 views

1 answer to this question.

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 May 1, 2018 by sharth
• 3,370 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,220 points
16,218 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,190 points
1,958 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,140 points
1,398 views
0 votes
2 answers

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,190 points
63,360 views
0 votes
1 answer

difference between wait() and sleep() in java

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

answered Apr 26, 2018 in Java by developer_1
• 3,350 points
1,212 views
+1 vote
1 answer

Multithreading in Java with priorities

HI, @Juan, By default, a thread inherits the priority of its parent thread. ...READ MORE

answered Nov 6, 2020 in Java by Gitika
• 65,770 points
2,545 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 17, 2018 in Java by code.reaper12
• 3,500 points
1,800 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,370 points
1,101 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,920 points
4,021 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP