Difference [interview questions] abstract classes and interfaces

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/jhl19981125/article/details/102752889

Abstract class (abstract class) and interfaces (interface) What are the similarities and differences?

Abstract class:
1. abstract class constructor can be defined in
2 can abstract methods and specific methods
3. The interface members are all the public
4. The abstract class member variable can be defined in
5. The method of abstract class must be declared is an abstract class, an abstract class may not have the abstract methods
6. the abstract class may contain static methods
7. a class can inherit an abstract class
interfaces:
1. the interface is not defined in the constructor
2. the method of abstract methods are all
3 abstract class member may be a private, default, protected, public
member variable defined in the interface 4 are actually constants
5. the interface can have a static method
6. a class can implement multiple interfaces
same:
1. not can instantiate
2. may abstract class and interface type as a reference type
3. If a class inherits an abstract class or implements an interface requires abstract of the approaches to achieve full, otherwise the class still need to be declared abstract class

Guess you like

Origin blog.csdn.net/jhl19981125/article/details/102752889