What is the difference between ‘ extends Thread’ and ‘implements Runnable’ ? Which one is advatageous

Java related questions and answers
deepak singh
Posts: 686
Joined: Fri Sep 30, 2016 4:19 pm

What is the difference between ‘ extends Thread’ and ‘implements Runnable’ ? Which one is advatageous

Postby deepak singh » Thu Oct 06, 2016 4:21 pm

What is the difference between ‘ extends Thread’ and ‘implements Runnable’ ? Which
one is advatageous

rameshkhd
Posts: 1279
Joined: Sun Aug 28, 2016 10:45 am

Re: What is the difference between ‘ extends Thread’ and ‘implements Runnable’ ? Which one is advatageous

Postby rameshkhd » Thu Oct 06, 2016 4:22 pm

Ans). extends Thread and implements Runnable – both are functionally same. But when we write
extends Thread, there is no scope to extend another class, as multiple inheritance is not supported in
Java. Class Myclass extends Thread, AnotherClass //invalid If we write implements Runnable, then
still there is scope to extend another class. class Myclass extends AnotherClass implements Runnable
//valid
This is definitely advantageous when the programmer wants to use threads and also wants to access
the features of another class


Return to “Java”

Who is online

Users browsing this forum: No registered users and 1 guest