Inheritance

Overview

Python, like most object oriented programming languages, supports inheritance. Inheritance is the transfer of characteristics of a class to other classes. Similar to biological inheritance where the child has characteristics of their parents. In this lab we will demonstrate inheritance and how it is used to neatly organize code. In this lab we will build off the pingscanner class (defined in the Creating a Ping Scanner lab) and illustrate a new child class called portscanner to demonstrate inheritance. We will use a script called portscanTest.py to import the portscanner module and demonstrate how methods are inherited from the parent class (pingscanner).

outcomes:

In this lab, you will learn to:

  1. Understand inheritance.
  2. Understand how inheritance and modules are used by Python to neatly organize code.
  3. Illustrate how Python can be used with other programming languages to automate tasks.

Key terms and descriptions

class
A class is a template.
object
An object is an instance of a class.
properties
Properties are the variables of a class.
methods
Methods are functions of the class.
inheritance
Inheritance is a concept in the object-oriented paradigm that allows for a child to inherit properties and methods of its parent.