java 面试题 抽象类与接口的区别 答案描述不够完整
Similarities: 1. Both can have abstract methods. 2. Neither can be instantiated. Differences: 1. An interface needs to be implemented by a class using the implements keyword, and supports multiple inheritance between interfaces and multiple implementation between classes and interfaces. An abstract class needs to be inherited by a subclass using the extends keyword, and only supports single inheritance. 2. An interface can only have constants, which are by default marked with public final static. An abstract class can have both ordinary variables and constants. 3. An interface supports default methods and static methods in JDK 1.8, and private methods in JDK 1.9, while the rest are abstract methods. An abstract class can have any methods. 4. An interface has no constructors, while an abstract class has constructors but cannot be instantiated, only for subclasses to create objects. 5. An interface cannot have an initial code block, while an abstract class can.
内容来源: crisxuan/bestJavaer