Java Threading: How does implementing runnable work for threading

前端 未结 5 1166
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 00:50

    In terms of functionality, there is no difference between implementing Runnable interface or extending Thread class. But there might be situations that implementing Runnable interface could be preferred. Think of the case that your class has to inherit from some other class and also it should show thread functionality. Since your class cannot inherit from multiple classes(Java doesn't support it), your class could implement Runnable interface in that case.

提交回复
热议问题