Inheritance
- Inheritance: allows for an object type to inherit features from another object type
- Reusability: Inheritance avoids having to rewrite much of the same code
- Maintenance: Code is easier to maintain. Changes in one part of a class are immediately implemented in other parts of a class
Derived Classes
- Define a general class (Base Class)
- Define specialised classes (Derived Classes) with unique features

Inheritance Syntax
- Syntax for a derived class definition:
class DerivedClassName(BaseClassName):
pass
- The name
BaseClassName
must be defined in a scope containing the derived class definition
e.g.
# base or parent class
class Device:
pass
# derived or child class
class Emitter(Device):
pass
# derived or child class
class Sensor(Device):
pass


Execution of Derived and Base Classes
- When a Derived Class Object is constructed, any base class inherited is remembered
- Execution of a derived class definition proceeds the same as for a base class
- If a requested attribute is not found in a class:
- the search proceeds to look in the Base Class (if specified)
- and occurs recursively if the Base Class itself is derived from some other class
- Derived Classes may override methods of their Base Classes

Inheritance Example I

- To inherit: do not list the method in the derived class
- To redefine (override): write the method in the derived class using the same name in the base class
- e.g.
__init__()
, __str__()
- to add a new attribute or method: code them in as you would in any class
- e.g.
width
, height
, area()
, circum()