In object oriented programming we can inherit the public method of one class into another class, which is called inheritance. This helps to avoid writing the same code again. In inheritance there are two main classes: Base class, and Derived class. Derived class inherits the public functions of a base class.