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

edited Apr 30, 2018 by developer_1 88 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,320 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
450 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
116 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
46 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 5 days ago in Java by Sirajul
• 17,240 points
85 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,280 points
57 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
110 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
72 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,320 points
42 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,850 points
75 views