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

edited Apr 30, 2018 by developer_1 491 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 Apr 30, 2018 by sharth
• 3,350 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
5,297 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,170 points
779 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,110 points
412 views
0 votes
2 answers

What is the difference between Set and List in java?

LIST SET Duplicates YES NO Order Ordered Depends on Implementation Positional Access YES NO List is an ordered sequence ...READ MORE

answered Aug 14, 2019 in Java by Sirajul
• 59,070 points
9,003 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,310 points
276 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,950 points
423 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,500 points
985 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,350 points
303 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,900 points
1,312 views