Always feel that they are two things is not a thing, a kind of chaotic feeling.
Reply to discussion (solution)
Abstract class
A series of methods are defined, and the methods that must be implemented by the inheriting class are defined. Abstract classes cannot be instantiated due to the existence of an abstract method
Abstract classes can be understood as the blank room, doors and windows, wall style by yourself to decide
So the difference between an abstract class and a normal class as a base class is that it's more restrictive.
Interface class
Similar to an abstract class, a method that is defined in an interface must be implemented by a reference class
But the fundamental difference between him and the abstract class is the use: the rules of communication with different individuals (methods)
You need a key to enter the dorm, and this key is your connection to the dorm.
Your same room also has this interface, so he can also enter the dormitory
You talk on your cell phone, so the phone is your interface to communicate with others.
1. An interface is a variant of an abstract class, and all methods in an interface are abstract. Abstract classes can have non-abstract methods. An abstract class is a class that declares the existence of a method without implementing it.
2. Interfaces can inherit, abstract class not.
3. The interface defines the method, there is no implementation of the code, and the abstract class can implement some methods.
4. The basic data type in the interface is static and the suction class is not.
5. Interfaces can inherit, abstract class not.
6. Multiple interfaces can be implemented in one class at the same time.
7. The interface is used by the Implements keyword, the abstract class is inherited by the extends keyword