Difference between Abstract class and interface

来源:互联网 发布:森山大道知乎 编辑:程序博客网 时间:2024/06/04 18:31

Unlike interfaces,abstract classes can contain fields that are not static and final, and they can contain

implemented methods. Such abstract classes are similar to interfaces, except that they provide a partial

 implementation, leaving it to subclasses to complete the implementation. If an abstract class containsonly abstract

 method declarations, it should be declared as an interface instead.

Multiple interfaces can be implemented by classes anywhere in the class hierarchy, whether or not they are

 related to one another in any way. Think of Comparable or Cloneable, for example.

By comparison, abstract classes are most commonly subclassed to share pieces of implementation. A single

 abstract class is subclassed by similar classes that have a lot in common (the implemented parts of the abstract

 class), but also have some differences (the abstract methods).

0 0
原创粉丝点击