I. The difference between an interface and an abstract class
Abstract class defines two methods, the interface can also define two methods, then at the time of definition, is the definition of abstract class or interface?
Inheritance and implementation are two different things.
Smoking is not the basic function of students, it is the extension function of students. If the student wants to smoke, it realizes the interface.
Class in determining the system, interfaces in determining the system's additional functionality.
For example,
According to the previously described knowledge, the program can write this, but we have made an improvement on it
What is the difference between the function of guiding blindness and the extraction of it? It seems to be easier not to extract them individually. But the thought is not that only the guide dog has the function of blindness, and other animals have this function.
I inherit the dog, inherit the basic function of the dog, inherit the guide blindness, it has the Guide function, but can not inherit more. Although the inheritance is not possible, but the interface can.
In this way, the two are clearly divided. This abstract class of dogs defines the most basic functions of a canine animal. Use classes to define basic functions, and in the area of problem analysis, blindness should be an extra function. The final form is shown below.
If the blind guide interface is not to be canceled, the guide is written to the guide dog, then the program is not extensible. Another point of view, if all the guide putschism can be set in the sub-class, Guide dogs, guide The Blind Cat, guide the Blind Pig. For all three to appear, to the next three orders, guide dogs on the Blind, guide the cat, on the Blind Pig. This brings the problem, there is common content, does not improve the reusability. Two, so to speak, all have guide blindness, all give me to go, so very simple answer. How the guide came from these species is constantly being extracted, which shows the benefits of extracting the guide function.
Let's talk about some of the analysis in the problem area.
Java-Preliminary Understanding-The Nineth chapter-the difference between an interface and an abstract class