A little thought about inheritance
In Java, inheritance is a way to implement reuse, although many times it is not recommended to use inheritance, but it is undeniable that sometimes it makes inheritance easier to understand a design
I have encountered such a situation, the general operation of object class A instance, but will occasionally operate some instances of Class B, b large part of the attribute A is included, this time using inheritance, should be no problem (at least I now understand that there is no problem, you teach), now put some instances of a and B into an array a[] As in, now to turn the AS, and the B do some operations, this time, you can use instanceof to determine whether B, and then into a B operation, do not know why, the mind is always a bit inconsistent instanceof so I thought of a method, in a and B to add a function IsB () so that you can avoid using instanceof.
In fact, there are some ways to make the operations of B a member function of B, also add a member function with the same name in a, so you can avoid using instanceof, but I think this member function is a unique function of B M1, A.M1 does not have any meaning, feel or add a IsB () More appropriate.