Java Threading: How does implementing runnable work for threading

前端 未结 5 1164
Happy的楠姐
Happy的楠姐 2021-02-10 00:21

I understand that if you want to thread you can either extend thread or implement runnable to multithread in java. But why do you have to implement an interface for java to thre

5条回答
  •  孤独总比滥情好
    2021-02-10 01:13

    But why do you have to implement an interface for java to thread?

    When you create a thread extending class Thread, You can no more extend any other class(multiple inheritance). On the other hand, If you use Runnable,you get the inheritance benefits of extending any class, if needed.

    In addition to above you also get memory and performance level benefits.

提交回复
热议问题