From fa7f5c024898c072c68c5a919eda0fc5246d8125 Mon Sep 17 00:00:00 2001 From: d-s-1 <31262406+d-s-1@users.noreply.github.com> Date: Wed, 4 Oct 2017 23:08:14 -0500 Subject: [PATCH] For example vs. ex. Used "for example," instead of "ex." per discussion. --- oop.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/oop.md b/oop.md index eb609902..b6a1f393 100644 --- a/oop.md +++ b/oop.md @@ -165,11 +165,11 @@ Output: **How It Works** -To use inheritance, we specify the base class names in a tuple following the class name in the class definition (ex. `class Teacher(SchoolMember)`). Next, we observe that the `__init__` method of the base class is explicitly called using the `self` variable so that we can initialize the base class part of an instance in the subclass. This is very important to remember- Since we are defining a `__init__` method in `Teacher` and `Student` subclasses, Python does not automatically call the constructor of the base class `SchoolMember`, you have to explicitly call it yourself. +To use inheritance, we specify the base class names in a tuple following the class name in the class definition (for example, `class Teacher(SchoolMember)`). Next, we observe that the `__init__` method of the base class is explicitly called using the `self` variable so that we can initialize the base class part of an instance in the subclass. This is very important to remember- Since we are defining a `__init__` method in `Teacher` and `Student` subclasses, Python does not automatically call the constructor of the base class `SchoolMember`, you have to explicitly call it yourself. In contrast, if we have not defined an `__init__` method in a subclass, Python will call the constructor of the base class automatically. -While we could treat instances of `Teacher` or `Student` as we would an instance of `SchoolMember` and access the `tell` method of `SchoolMember` by simply typing `Teacher.tell` or `Student.tell`, we instead define another `tell` method in each subclass (using the `tell` method of `SchoolMember` for part of it) to tailor it for that subclass. Because we have done this, when we write `Teacher.tell` Python uses the `tell` method for that subclass vs the superclass. However, if we did not have a `tell` method in the subclass, Python would use the `tell` method in the superclass. Python always starts looking for methods in the actual subclass type first, and if it doesn’t find anything, it starts looking at the methods in the subclass’s base classes, one by one in the order they are specified in the tuple (here we only have 1 base class, but you can have multiple base classes) in the class definition. +While we could treat instances of `Teacher` or `Student` as we would an instance of `SchoolMember` and access the `tell` method of `SchoolMember` by simply typing `Teacher.tell` or `Student.tell`, we instead define another `tell` method in each subclass (using the `tell` method of `SchoolMember` for part of it) to tailor it for that subclass. Because we have done this, when we write `Teacher.tell` Python uses the `tell` method for that subclass vs the superclass. However, if we did not have a `tell` method in the subclass, Python would use the `tell` method in the superclass. Python always starts looking for methods in the actual subclass type first, and if it doesnÂ’t find anything, it starts looking at the methods in the subclassÂ’s base classes, one by one in the order they are specified in the tuple (here we only have 1 base class, but you can have multiple base classes) in the class definition. A note on terminology - if more than one class is listed in the inheritance tuple, then it is called **multiple inheritance**.