Chapter 9 (Objects advanced)

Inheritance

What is messaging an object?

This is when an object sends a message to another via invoking one of there methods

What is inheritance?

This is where a class will copy all the methods and attributes of another class

What is the syntax for making a parent the super class of a child?
class Parent:
    def __init__(self):
        self.name = 'jim'

class child(Parent):
    def __init__(self):

kid = child()
print(kid.name)
#returns an error
  • Here the parent is the super class, child has not yet inherited its attributes and methods
How to inherit from the super class?
class Parent:
    def __init__(self):
        self.name = 'jim'

class child(Parent):
	pass

kid = child()
print(kid.name)
#returns 'jim'

Modules

What is polymorphism?

This is where you can use similar methods, for different classes

How do i create a module?
  1. create a python file
  1. create functions and classes within the file
  1. make sure that its in the same folder as the main python file
  1. import the file on the main python file
  1. DONE!!!