java extends & implements 一个一般不会注意到的重要区别

来源:互联网 发布:淘宝店铺音乐 编辑:程序博客网 时间:2024/05/17 03:38

Well so many good Answers, i want to add more on this, This will help to understandExtending v/s Implementing Thread_
Extends binds two class files very closely and can cause some pretty hard to deal with code.

Both approaches do the same job but there have been some differences.
The most common difference is

  1. When you extends Thread class, after that you can’t extend any other class which you required. (As you know, Java does not allow inheriting more than one class).
  2. When you implements Runnable, you can save a space for your class to extend any other class in future or now.

However, one significant difference between implementing Runnable and extending Thread is that
by extending Thread, each of your threads has a unique object associated with it, whereas implementing Runnable, many threads can share the same object instance.


   我好懒,不想翻译了,哈哈

0 0