(1) Both abstract classes and interfaces can have abstract methods.
(2) Interfaces can only have constants, not variables, while abstract classes can have both constants and variables.
(3) Abstract classes can also have non-abstract methods, but interfaces cannot.
When designing a program, you should determine whether to use abstract classes or interfaces based on specific analysis. In addition to providing important abstract methods that need to be overridden by subclasses, abstract classes also provide variables and non-abstract methods that subclasses can inherit.
If a certain problem needs to be better solved using inheritance, for example: in addition to overriding the abstract method of the parent class, the subclass also needs to inherit some variables or inherit some important non-abstract methods from the parent class, you can consider using abstract kind. If a certain problem does not require inheritance, but only requires several classes to provide the implementation details of some important abstract methods, you can consider using interfaces.
Note : JDK1.8 interface supports static methods and default methods.
1) Interfaces cannot be used to instantiate objects.
2) The interface has no constructor method.
3) All methods in the interface must be abstract methods.
4) Interfaces cannot contain member variables, except static and final variables.
5) The interface is not inherited by the class, but implemented by the class.
6) The interface supports multiple inheritance.
The default method means that the interface can have implementation methods and does not need an implementation class to implement its methods. You only need to add the default keyword in front of the method name to implement the default method. Default methods provide a way to extend an interface without breaking existing code.
(1) An interface can have multiple default methods and static methods.
(2) The default method is called through the instance, and the static method is called through the interface name.
(3) The default keyword can only be used in interfaces.
(4) Default methods can be inherited. If you inherit multiple interfaces and multiple interfaces define multiple same default methods, the implementation class needs to override the default methods, otherwise an error will be reported.
(5) Static methods cannot be inherited and overridden, so they can only be called by the specific interface.
Note : After JDK 1.9, methods are allowed to be defined as private, so that certain reused codes will not expose the methods.