We know that in JavaAbstract classAndInterfaceThe flexible use of C ++ greatly simplifies multiple inheritance in C ++, but Implements similar functions in C ++, in fact, the use of interfaces is only a manifestation of the lower-level data transfer in class hierarchies. We can imagine a family relationship in Java.
Of course, the parent class object is your ancestor,
Abstract class ):
Abstract classes are of course your grandfathers (grandfathers, grandfathers), and abstract methods in abstract classes are like what your grandfathers should do, but they do not have the ability to do it, or they do not want to do it at all (maybe they have this dream, but they do not have the ability ), fortunately, their final children and grandchildren (not abstract classes anymore) are capable and promising children and grandchildren who help them complete what they have not done (implementing abstract methods ), if one day you want to ask these grandfathers to do things that they just haven't done (call abstract methods), these grandfathers will tell you, ah, I can't do this, I have already asked my son to take charge of it. If you go to my son, the person has to find his son. If this son doesn't have the ability (or abstract class ), he may tell the person again that I cannot do these things (and abstract methods). I asked my son to do it. You can find him ........ so far, the person can only keep looking for it and find the son capable of completing these tasks (the abstract method has been implemented ), then let this son go there (call this implementation method). Of course, these grandfathers have done most of the things (most of them are not abstract methods ), at the same time, they also have their own personality, appearance, height, and so on (these are attributes ).....
2 interface ):
The interface is even better (only attributes, there is no method body at all). They are all easy to eat and do, and there is no such thing as an ancestor (of course, they still have appearances and weights in this world, height, hobbies, and other features...),] originally, God gave them a lot of things to do (Methods in interfaces), and they were too lazy to do it (maybe it's easy to get used to it, haha, is this metaphor accurate ), however, they all have a strong strength. They have a very strong son-bearing ability (the class that implements these interfaces or the derived sub-interfaces). If you are lucky, a diligent and promising son (class that implements interfaces) may be born. This son will give an overview of all these lazy grandfathers, all of them to help them complete (implement all the methods in the interface), of course, if the operation is not good, the generated son is not the same as him, it will also become more severe (there may be more methods without method bodies), and so on ...... haha, but in the end all their children and grandchildren are promising, and they will take their grandparents (there may be grandpa Zeng, grandpa, Dad, [Uncle, Uncle, maybe a little inaccurate, but Java can implement multiple interfaces. I can only understand this]) All the things left behind are done. just like a group, when some people want these lazy grandparents to do what they should do, they will be impatient to tell you that I am looking for my son (or nephew) let's go. I am solely responsible for it, and the man has to look for his son ...., in the end, the person found the best child of the lazy ancestors (class implementing these interfaces ), let this descendant do those things (when using the interface reference to call the interface method)
These are my personal understandings of Java. If any of you have different opinions on this, I hope I can point out what is wrong with it and discuss it together.