EC Lecture Notes - Lecture 5: Init, Dna, Instance Variable

11 views5 pages

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())

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents