Runnable interface over Thread class

I just wanted to ask that is the runnable interface is implemented just so that the class can realise the concept of multiple inheritance ,because if our class extends thread class,then our class won't be able to extend any other class,so can anyone plz tell ,is there any advantage other than this..

Replies

  • Sanyam Khurana
    Sanyam Khurana
    radha gogia
    I just wanted to ask that is the runnable interface is implemented just so that the class can realise the concept of multiple inheritance ,because if our class extends thread class,then our class won't be able to extend any other class,so can anyone plz tell ,is there any advantage other than this..
    Strictly speaking, multiple inheritence is not supported in Java.

    AFAIK, in many books the concept of threading says that multiple inheritence is supported, but that's not the case. (I would like to clear this from CEans here, if I'm wrong 😀 )

    To inherit properties of any class, we extend it. Implementing an interface is a different concept all together.

    While Thread class is extended, all it's data members and member functions (methods) would be inherited like setName() method etc. which can create an extra overhead if they are not needed. Hence, Runnable Interface would be preferred.

    Though if you want to use the methods, they why not use it by extending Thread class instead. Right?

    PS: Tagging #-Link-Snipped-# to shed some light on the topic.
  • Anoop Kumar
    Anoop Kumar
    To be concise:
    If you implement Runnable interface your code is flexible which can extend a class. If you want to dug more here is #-Link-Snipped-#.
    Write few program you will understand which one is suitable.

    Inheritance:
    IMO saying implementing a interface is inheritance, is wrong. When you inherit something you inherit actual property not just the name. Classes have actual property (method), interfaces just have names.

You are reading an archived discussion.

Related Posts

Descriptions are superfluous: https://www.ba-bamail.com/Content.as...7nDOhAuOgGVeVroA7UqfrRJUc9NNRxaPrGJsT0=&d=294
i filled up everything but, after selecting examination center 1 , i cant select Choice of Examination City 2 and Choice of Examination City 3 , nothing shows when i...
Quote: One of the top medical device conferences - AdvaMed 2014 - concluded in Chicago, Wednesday and a few themes emerged around an industry that is witnessing seismic changes in...
Click Labs is privately held Information Technology and Services company founded by Samar Singla, Chinmay Agarwal, Parag Jain, Sanjay Dhakar and Rohit Goyal in the year 2011. Click Labs is...
OnePlus, the company that never settles, has announced JBL E1+ earphones with a price tag of $39.99. The earphones are expected to be available towards the end of this month...