Difference Between Abstract Class and Interface Class

Difference Between Abstract Class and Interface Class

 1. There are similarities between interfaces and abstract classes

Both interfaces and abstract classes cannot be instantiated, and are located at the top of the inheritance tree. They are used to be instantiated by other classes, and both can have abstract methods.

2. Differences

An interface can only contain abstract methods and default methods, and no implementation is provided. There can be ordinary methods in an abstract class.

Only static variables can be defined in the interface, and ordinary variables cannot be defined.

Both ordinary and static variables in abstract classes can be defined.

There are no constructors in interfaces but abstract classes can contain constructors.

Only single inheritance but can have multiple interface implementations.

Guess you like

Origin blog.csdn.net/weixin_41957626/article/details/131023181