For example, mountain bikes, race bikes and tandems are all different kinds of bicycles. In object-oriented terminology, mountain bikes, race bikes and tandems are all subclasses of the bicycle class. Similarly, the bicycle class is the superclass of mountain bikes, race bikes and tandems. Also, each subclass inherits methods from the superclass. However, subclasses are not limited to the state and behaviours provided to them by their superclass.
Subclasses can add variables and methods to the ones they inherited from the superclass.
Subclasses can also override inherited methods and provide specialized implementations for those methods. Methods and variables are inherited down through the levels. The further down in the hierarchy a class appears, the more specialized its behaviour. The Benefit of Inheritance Subclasses provide specialized behaviours from the basis of common elements provided by the superclass. Through the use of inheritance, programmers can reuse the code in the superclass many times.