Click to enter _ many other _java thousand ask
1. What is the difference between an interface and an abstract class?
In the Java language. Abstract class and interface interface are two mechanisms of abstract definition.
It is the existence of these two mechanisms that gives Java a powerful object-oriented capability. Abstract class and interface interface are very similar in terms of abstraction definitions. Can even replace each other. So a lot of developers are more selective when it comes to abstract definitions. In fact, there is a very big difference between the two. Their choice can reflect the understanding of the nature of the problem and the understanding of the design intent.
Learn about Abstract classes here: How abstract concepts in Java are embodied
Understanding the interface look here: What exactly is the interface in Java
Learn a lot about other inheritance see here: what is the meaning of Java class inheritance?
Details such as the following:
Learn about the is-a,has-a,like-a relationship look here: what is is-a,has-a,like-a
2, interface application in what occasions
- Classes and classes require a specific interface to reconcile, regardless of how they are implemented.
- As an identity that is capable of implementing a specific function, it can also be a purely identifier for what interface methods do not exist. such as serialized interface: Serializable
- A set of classes needs to be treated as a single class, and the caller is only connected to this set of classes through an interface.
- There is a need to implement a specific number of functions that may not have any connection whatsoever.
3. What is the application of abstract class?
- Defines a set of interfaces, but does not want to force every implementation class to implement all interfaces.
The ability to define a set of method bodies, even an empty method body, with the abstract class, and then select the methods that are of interest to the subclasses to overwrite them.
- Some occasions. A purely interface does not satisfy the coordination between classes and classes, and the attributes that represent states in a class are required to discriminate between different relationships.
- Standardize a set of mutually coordinated methods. Some of these methods are common. State-Independent, sharable, without subclasses, and there are methods that require individual subclasses to implement specific functions based on their own specific state.
Java thousands ask _05 object-oriented (005) _ Interface and abstract class what is the difference