The first thing about using the OO language in Java is that if the class is not designed to be inherited, try not to use the combination
From 2, our class B makes a copy of the add of Class A to drink the AddAll method, so that we can count the number of calls to Class A every time we call it, and we actually call Class B.
But the count variable of instance object B becomes 2, explaining the reason in Figure 1 I have done a blackboard painting, this example is effective Java inside a piece of advice, very meaningful,
Less inheritance, unless classes are specifically used to inherit, such as the activity classes in Android development are specifically designed for inheritance, these classes can be used for inheritance, and some classes that are not specifically designed for inheritance
Use the compound as much as possible, so that it does not confuse.
<<effective java>> the best use of combination rather than inheritance