Interface(interface) can be said to be
Abstract classA special case in which all methods in an interface must be abstract. The method definition in the interface defaults to the public abstract type, and the member variable type in the interface defaults to public static final. In addition, interfaces and abstract classes have
difference: 1. Abstract classes can have construction methods, and interfaces cannot have constructors. 2. Abstract classes can contain non-abstract ordinary methods, all the methods in the interface must be abstract, and cannot have non-abstract ordinary methods. 3. There can be ordinary member variables in an abstract class, and there is no ordinary member variable 4 in the interface. The access type of an abstract method in an abstract class can be public,protected and the default type of 5. A static method can be included in an abstract class, and the interface cannot contain static method 6. Both abstract classes and interfaces can contain static member variables, and the access type of static member variables in an abstract class can be arbitrary, but the variables defined in the interface can only be public static final types, and public static final type 7 is the default. A class can implement multiple interfaces, but can inherit only one abstract class. There are also some differences in application: The interface is more in the system architecture design method to play a role, mainly used to define the communication contract between the modules. Abstract classes play a role in the implementation of code, can implement code reuse, for example, template method design pattern is a typical application of abstract class, it is assumed that all the servlet classes of a project to use the same way to determine permissions, log access logs and handle exceptions, you can define an abstract base class, Let all servlets inherit this abstract base class, and in the service method of the abstract base class, complete the permission judgments, log access logs, and code that handles exceptions, and only complete their own business logic code in each subclass.
The difference between an abstract class and an interface