However, comments are wonderful since there is more than one way to write a segment of code, comments would help in deciphering the algorithm. Another feature of object-oriented programming is the concept of inheritance. The idea behind this concept is that if a class is written, then a sub class may be written and that subclass will inherit all of the qualities of the parent class. An analogy of this would be that squares are subclasses of rectangles and that rectangle are subclasses of parallelograms and that parallelograms are subclasses of quadrilaterals. To demonstrate inheritance, I ll use the given shape analogy.
All quadrilaterals have four sides.
So all parallelograms have fours side, but they also have the property that opposite sides never intersect while adjacent side do. Rectangles have inherited the properties of quadrilaterals and parallelograms and they have their own unique property that all angles formed between adjacent sides are ninety degrees in measure. Finally, squares inherit the properties of quadrilaterals, parallelograms and rectangles and they have their own property that all side must be equal in length. This example illustrates single inheritance because all of the classes have only one parent class, but notice that they have more than one ancestor. An example of multiple inheritance would be the combining of a square and a triangle to form a pyramid.