EC Lecture Notes - Lecture 5: Init, Dna, Instance Variable
Document Summary
Inheritance is the capability of one class to derive or inherit the properties from another class. We don"t have to write the same code again and again. Also, it allows us to add more features to a class without modifying it. It is transitive in nature, which means that if class b inherits from another class a, then all the subclasses of b would automatically inherit from class a. Below is a simple example of inheritance in python. A class that inherits from another class is called a subclass. A class that is inherited from is called a superclass. # to check if this person is an employee def isemployee(self): return false. # inherited or subclass (note person in bracket) class employee(person): # here we return true def isemployee(self): return true. # driver code emp = person("geek1") # an object of person print(emp. getname(), emp. isemployee()) emp = employee("geek2") # an object of employee print(emp. getname(), emp. isemployee())