for exampleif we are building system to keep track of employeeswe might have class employee that contains the general information that is common to all employees one example attribute would be homeaddress method that returns the home address of an employee within the class of all employeeswe might distinguish between salariedemployee and hourlyemployee we could make these subclasses of employeeso they would share methods like homeaddress howevereach subclass would have its own monthlypay functionsince pay is computed differently for these different classes of employees inheritance provides two benefits one is that we can structure the classes of system to avoid duplication of operations we don' have to write separate homeaddress method for the hourlyemployee and salariedemployee classes closely related benefit is that new classes can often be based on existing classespromoting code reuse we could have used inheritance to build our poker program when we first wrote the dieview classit did not provide way of changing the appearance of the die we solved this problem by modifying the original class definition an alternative would have been to leave the original class unchanged and create new subclass colordieview colordieview is just like dieview except that it contains an additional method that allows us to change its color here is how it would look in pythonclass colordieview(dieview)def setvalue(selfvalue)self value value dieview setvalue(selfvaluedef setcolor(selfcolor)self foreground color self setvalue(self valuethe first line of this definition says that we are defining new class colordieview that is based on ( subclass ofdieview inside the new classwe define two methods the second methodsetcoloradds the new operation of coursein order to make setcolor workwe also need to modify the setvalue operation slightly the setvalue method in colordieview redefines or overrides the definition of setvalue that was provided in the dieview class the setvalue method in the new class first stores the value and then relies on the setvalue method of the superclass dieview to actually draw the pips notice especially how the call to the method from the superclass is made the normal approach self setvalue(valuewould refer to the setvalue method of the colordieview classsince self is an instance of colordieview in order to call the original setvalue method from the superclassit is necessary to put the class name where the object would normally go dieview setvalue(selfvaluethe actual object to which the method is applied is then sent as the first parameter