CrazyEngineers
  • Runnable interface over Thread class

    radha gogia

    Member

    Updated: Oct 24, 2024
    Views: 1.3K
    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..
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Sanyam Khurana

    MemberOct 12, 2014

    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.
    Are you sure? This action cannot be undone.
    Cancel
  • Anoop Kumar

    MemberOct 12, 2014

    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.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register