Difference between Abstract class and interface
2014-03-04 15:30
435 查看
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 contains
only 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).
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 contains
only 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).
相关文章推荐
- difference between Abstract class and interface in java
- Java - Difference between Abstract class and Interface
- Differences between abstract class and interface
- 【转载】#445 - Differences Between an Interface and an Abstract Class
- Difference between Abstract Class and Interface in Java
- What’s the difference between an interface and an abstract class in Java?
- difference between Interface and abstract class in Java
- difference between Abstract class and interface in java
- What is difference between abstract class and interface
- difference between abstract class and interface
- Different Between An Interface and An Abstract Class
- 【转载】#446 - Deciding Between an Abstract Class and an Interface
- Summary: Arrays vs. Collections && The differences between Collection Interface and Collections Class
- the Differences between abstract class & interface in C#接口和抽象类的区别
- Interface And Abstract Class
- What is the difference between Class Path and Build Path
- interface and abstract class
- [php] Interface abstract里面的私有方法 -- private method of interface and abstract class
- 单例模式和静态类的区别(Difference between static class and singleton pattern)
- Java Abstract class and Interface