Hiring Partners
Segilola Resources Operating LimitedTaviatech TechnologiesFCMBMTN NigeriaAdvans La Fayette Microfinance BankAboki AfricaFirst Bank of NigeriaOPay
← Fundamentals of Object Oriented Programming Level One · Lesson 4 of 6

Module Three

📖 Every lesson in this course is free to read right here, no account needed. Create a free account to track your progress, take the exam, and earn your certificate.
4
Module Three · Object Oriented Programming

📘 Module Three: Inheritance and Polymorphism – Building on What You Know

🌟 Module Introduction

Welcome back, programmer! In Module One, you learned what Object Oriented Programming is. You learned about objects and classes. In Module Two, you learned how to write classes and create objects in Python. You learned about __init__, self, attributes, and methods.

Now imagine you want to create a program about animals. You have dogs, cats, and birds. They all have names and ages. They all eat and sleep. But dogs can bark. Cats can meow. Birds can fly. Do you want to write the same code for name, age, eat, and sleep three times? That would be a lot of work.

This is where inheritance comes in. Inheritance lets one class get all the data and methods from another class. Then you can add new things or change things. It saves time and keeps your code organised.

We will also learn about polymorphism. Polymorphism means “many forms”. It lets different objects respond to the same action in their own way. A dog barks. A cat meows. Both respond to “make a sound”, but in different ways.

By the end of this module, you will be able to create parent classes and child classes. You will understand how to reuse code. You will see how polymorphism makes programs flexible. Let’s begin!

🎯 Learning Objectives

After you finish this module, you will be able to:

  • Explain what inheritance is.
  • Explain why inheritance is useful.
  • Create a parent class.
  • Create a child class that inherits from a parent.
  • Add new attributes and methods to a child class.
  • Override methods in a child class.
  • Use the super() function to call the parent’s methods.
  • Explain what polymorphism is.
  • See polymorphism in action with different objects.
  • Understand the “is-a” relationship.
  • Avoid common mistakes with inheritance.
  • Feel confident to use inheritance in your own programs.

📖 Warm-up Story: Tunde and the Family of Cars

Tunde lived in Ibadan. His father owned a car workshop. One day, Tunde asked his father, “Papa, how do you build different types of cars? You have taxis, buses, and private cars. They are all different, but they all have wheels and engines.”

His father smiled. “That is a good question,” he said. “We start with a basic design. Every car has wheels, an engine, and a steering wheel. That is the parent design. Then, for a taxi, we add a taxi sign and a meter. For a bus, we add many seats. For a private car, we add comfortable seats.”

Tunde understood. “So the basic design is like a parent class,” he said. “And the taxi, bus, and private car are like child classes. They inherit from the parent, but they add their own special things.”

His father nodded. “Exactly! And here is the amazing part. If we need to change the engine design, we only change it in the parent design. All the child designs get the update automatically. That saves us a lot of work.”

Tunde was excited. He decided to learn more about inheritance. He wanted to write code that reused ideas, just like his father’s workshop.

Moral of the story: Inheritance lets you build on what you already have. You write common things once in a parent class, and child classes get them for free.

📚 Main Lessons

Lesson 1: What is Inheritance?

Definition: Inheritance is when one class gets the attributes and methods of another class.

Why it is important: It saves time. You write common code once, and reuse it many times.

Simple explanation: Imagine you have a recipe for bread. You can use that recipe to make different types of bread: white bread, brown bread, and banana bread. You do not need to write the basic bread recipe again. You just add the special ingredients.

Real-life example: A smartphone inherits from a basic phone. It can call and text (from the basic phone), but it can also take photos and browse the internet.

School example: A science student inherits from a student. They have a name and age (from student), but they also study science subjects.

Home example: A puppy inherits from a dog. It has fur and a tail (from dog), but it is smaller and drinks milk.

Nigerian example: A danfo bus inherits from a vehicle. It has wheels and an engine (from vehicle), but it also has yellow paint and a conductor.

Illustration:

  Parent Class: Vehicle
       |
       V
  +--------+ +--------+ +--------+
  | Car    | | Bus    | | Danfo  |
  +--------+ +--------+ +--------+
  Child Classes inherit from Vehicle
  

Mini summary: Inheritance lets one class get the data and actions of another class. It saves time and keeps code organised.

Lesson 2: Parent Class and Child Class

Definition: A parent class is the class being inherited from. A child class is the class that inherits.

Why it is important: You need to know the difference to use inheritance correctly.

Simple explanation: The parent class is like a mother. The child class is like her child. The child gets some things from the mother, but also has its own things.

Real-life example: A vehicle is a parent class. A car is a child class.

School example: A person is a parent class. A student is a child class.

Home example: An animal is a parent class. A dog is a child class.

Nigerian example: A trader is a parent class. A food trader is a child class.

Illustration:

  Parent Class: Animal
       |
       V
  Child Class: Dog
       |
       V
  Dog inherits from Animal
  

Mini summary: A parent class is inherited from. A child class inherits. The child gets things from the parent.

Lesson 3: The “Is-A” Relationship

Definition: Inheritance creates an “is-a” relationship. A child class “is a” type of parent class.

Why it is important: It helps you know when to use inheritance.

Simple explanation: A dog “is an” animal. A car “is a” vehicle. A student “is a” person.

Real-life example: A smartphone “is a” phone.

School example: A science student “is a” student.

Home example: A puppy “is a” dog.

Nigerian example: A danfo “is a” vehicle.

Illustration:

  Dog IS-A Animal  ✓
  Car IS-A Vehicle ✓
  Student IS-A Person ✓

  Dog IS-A Car     ✗ (not correct)
  

Mini summary: Inheritance creates an “is-a” relationship. If the child “is a” type of parent, inheritance makes sense.

Lesson 4: Creating a Parent Class

Definition: A parent class is a normal class that other classes will inherit from.

Why it is important: It holds the common code that all child classes will share.

Simple explanation: You write a class with common attributes and methods. Then child classes can use them.

Real-life example: A parent class called Animal with name and age.

School example: A parent class called Person with name and age.

Home example: A parent class called Appliance with brand and power.

Nigerian example: A parent class called Vehicle with wheels and engine.

Example code:

  class Animal:
      def __init__(self, name, age):
          self.name = name
          self.age = age

      def eat(self):
          print(self.name + " is eating.")

      def sleep(self):
          print(self.name + " is sleeping.")
  

Illustration:

  class Animal:
      __init__ -> name, age
      eat() -> "eating"
      sleep() -> "sleeping"
  

Mini summary: A parent class holds common attributes and methods. Child classes will inherit them.

Lesson 5: Creating a Child Class

Definition: A child class inherits from a parent class. You write the parent class name in parentheses.

Why it is important: Child classes get all the parent’s attributes and methods for free.

Simple explanation: You write class Dog(Animal):. The (Animal) means Dog inherits from Animal.

Real-life example: A child class called Dog inherits from Animal.

School example: A child class called ScienceStudent inherits from Student.

Home example: A child class called SmartPhone inherits from Phone.

Nigerian example: A child class called Danfo inherits from Vehicle.

Example code:

  class Dog(Animal):
      def bark(self):
          print(self.name + " is barking.")
  

Illustration:

  class Animal:
      name, age
      eat(), sleep()
       |
       V
  class Dog(Animal):
      bark()
  Dog inherits eat and sleep from Animal
  

Mini summary: A child class inherits from a parent by writing the parent’s name in parentheses.

Lesson 6: Adding New Methods to a Child Class

Definition: You can add new methods to a child class that the parent does not have.

Why it is important: It lets the child class do things that are special to it.

Simple explanation: A dog can bark. An animal cannot bark. So bark() is added only to the Dog class.

Real-life example: A smartphone can take photos. A basic phone cannot.

School example: A science student can do experiments. A normal student cannot.

Home example: A smart TV can browse the internet. A normal TV cannot.

Nigerian example: A danfo can carry many passengers. A private car cannot.

Example code:

  class Dog(Animal):
      def bark(self):
          print(self.name + " is barking.")

  my_dog = Dog("Bingo", 3)
  my_dog.eat()   # inherited from Animal
  my_dog.bark()  # added in Dog
  

Output:

  Bingo is eating.
  Bingo is barking.
  

Illustration:

  Animal: eat(), sleep()
  Dog: eat(), sleep() + bark()
  

Mini summary: Child classes can add new methods. These are special actions that only the child can do.

Lesson 7: Overriding Methods

Definition: Overriding means changing a method in the child class that already exists in the parent class.

Why it is important: Sometimes the child needs to do something differently.

Simple explanation: The parent says “eat”. The child says “eat differently”.

Real-life example: A baby eats milk. An adult eats rice. Both “eat”, but differently.

School example: A JSS1 student studies basic maths. A JSS3 student studies harder maths. Both “study”, but differently.

Home example: A puppy sleeps a lot. An adult dog sleeps less. Both “sleep”, but differently.

Nigerian example: A small trader sells from a tray. A big trader sells from a shop. Both “sell”, but differently.

Example code:

  class Animal:
      def __init__(self, name):
          self.name = name

      def speak(self):
          print(self.name + " makes a sound.")

  class Dog(Animal):
      def speak(self):
          print(self.name + " barks.")

  class Cat(Animal):
      def speak(self):
          print(self.name + " meows.")

  my_dog = Dog("Bingo")
  my_cat = Cat("Fluffy")

  my_dog.speak()  # Bingo barks.
  my_cat.speak()  # Fluffy meows.
  

Illustration:

  Animal.speak() -> "makes a sound"
  Dog.speak()    -> "barks"
  Cat.speak()    -> "meows"
  

Mini summary: Overriding means changing a method in the child class. The child does it differently.

Lesson 8: Using super() to Call the Parent

Definition: super() is a function that lets you call a method from the parent class.

Why it is important: Sometimes you want to use the parent’s method and then add more.

Simple explanation: You say “do what the parent does, then do this extra thing”.

Real-life example: A child says “Thank you” like their parent, then adds “sir” or “madam”.

School example: A student follows the school rules, then adds their own study rules.

Home example: You follow your family recipe, then add your own spice.

Nigerian example: You follow your mother’s jollof recipe, then add your own special pepper.

Example code:

  class Animal:
      def __init__(self, name, age):
          self.name = name
          self.age = age

      def introduce(self):
          print("I am " + self.name + " and I am " + str(self.age) + " years old.")

  class Dog(Animal):
      def __init__(self, name, age, breed):
          super().__init__(name, age)
          self.breed = breed

      def introduce(self):
          super().introduce()
          print("I am a " + self.breed + ".")

  my_dog = Dog("Bingo", 3, "Labrador")
  my_dog.introduce()
  

Output:

  I am Bingo and I am 3 years old.
  I am a Labrador.
  

Illustration:

  Dog.__init__
       |
       V
  super().__init__(name, age) -> sets name and age
       |
       V
  self.breed = breed -> sets breed
  

Mini summary: super() lets you call the parent’s method. You can use it and then add more.

Lesson 9: What is Polymorphism?

Definition: Polymorphism means “many forms”. It lets different objects respond to the same action in their own way.

Why it is important: It makes programs flexible. You can write one piece of code that works with many types of objects.

Simple explanation: If you say “speak” to a dog, it barks. If you say “speak” to a cat, it meows. Same action, different results.

Real-life example: If you press “play” on a phone, it plays music. If you press “play” on a video player, it plays video.

School example: If you say “write” to a student, they write with a pen. If you say “write” to a computer, it writes on the screen.

Home example: If you say “cook” to a microwave, it heats food. If you say “cook” to a cooker, it boils food.

Nigerian example: If you say “sell” to a food trader, they sell food. If you say “sell” to a cloth trader, they sell cloth.

Illustration:

  Action: speak()
       |
       V
  +--------+ +--------+ +--------+
  | Dog    | | Cat    | | Cow    |
  | barks  | | meows  | | moos   |
  +--------+ +--------+ +--------+
  Same action, different results!
  

Mini summary: Polymorphism means “many forms”. Different objects can respond to the same action in their own way.

Lesson 10: Polymorphism in Action

Definition: You can use polymorphism by calling the same method on different objects.

Why it is important: It lets you write flexible code.

Simple explanation: You write a loop that goes through a list of animals. You call speak() on each one. Each animal speaks in its own way.

Real-life example: A remote control has a “power” button. It works on the TV, the fan, and the air conditioner.

School example: A teacher says “introduce yourself”. Each student says their own name.

Home example: You say “clean” to your broom, your mop, and your vacuum. Each cleans differently.

Nigerian example: You say “cook” to your pot, your pan, and your oven. Each cooks differently.

Example code:

  animals = [Dog("Bingo"), Cat("Fluffy"), Cow("Buttercup")]

  for animal in animals:
      animal.speak()
  

Output:

  Bingo barks.
  Fluffy meows.
  Buttercup moos.
  

Illustration:

  for animal in animals:
      animal.speak()
       |
       V
  Dog.speak() -> barks
  Cat.speak() -> meows
  Cow.speak() -> moos
  

Mini summary: Polymorphism lets you call the same method on different objects. Each object responds in its own way.

Lesson 11: Inheritance and Polymorphism Together

Definition: You can use inheritance and polymorphism together.

Why it is important: This is the power of OOP.

Simple explanation: You create a parent class with a method. Child classes override the method. Then you can use polymorphism to call the method on any child.

Real-life example: A vehicle parent class has a move() method. Cars, buses, and bikes override it.

School example: A person parent class has a study() method. Science, art, and commercial students override it.

Home example: An appliance parent class has a work() method. Fridge, fan, and cooker override it.

Nigerian example: A trader parent class has a sell() method. Food, cloth, and phone traders override it.

Example code:

  class Vehicle:
      def __init__(self, name):
          self.name = name

      def move(self):
          print(self.name + " is moving.")

  class Car(Vehicle):
      def move(self):
          print(self.name + " is driving on the road.")

  class Boat(Vehicle):
      def move(self):
          print(self.name + " is sailing on the water.")

  class Plane(Vehicle):
      def move(self):
          print(self.name + " is flying in the sky.")

  vehicles = [Car("Toyota"), Boat("Canoe"), Plane("Boeing")]

  for v in vehicles:
      v.move()
  

Output:

  Toyota is driving on the road.
  Canoe is sailing on the water.
  Boeing is flying in the sky.
  

Illustration:

  Vehicle.move()
       |
       V
  Car.move()   -> driving
  Boat.move()  -> sailing
  Plane.move() -> flying
  

Mini summary: Inheritance and polymorphism work together. The parent defines the method. The children override it. Polymorphism calls it on any child.

Lesson 12: When to Use Inheritance

Definition: Inheritance is best when there is an “is-a” relationship and shared code.

Why it is important: Using inheritance wrongly makes code confusing.

Simple explanation: Use inheritance when the child “is a” type of parent and they share common things.

Real-life example: A car “is a” vehicle. Use inheritance. A car “has an” engine. Do not use inheritance; use an attribute.

School example: A student “is a” person. Use inheritance. A student “has a” bag. Do not use inheritance.

Home example: A dog “is an” animal. Use inheritance. A dog “has a” collar. Do not use inheritance.

Nigerian example: A danfo “is a” vehicle. Use inheritance. A danfo “has a” conductor. Do not use inheritance.

Illustration:

  IS-A relationship  -> Use inheritance
  HAS-A relationship -> Use attribute

  Dog IS-A Animal    -> inheritance
  Dog HAS-A Collar   -> attribute
  

Mini summary: Use inheritance for “is-a” relationships. Use attributes for “has-a” relationships.

Lesson 13: Types of Inheritance

Definition: There are different ways classes can inherit from each other.

Why it is important: Knowing the types helps you design your classes.

Simple explanation: You can have single inheritance (one parent), multilevel inheritance (parent, child, grandchild), and multiple inheritance (many parents).

Real-life example: A grandfather, a father, and a son are multilevel inheritance.

School example: A person, a student, and a science student are multilevel inheritance.

Home example: An appliance, a kitchen appliance, and a fridge are multilevel inheritance.

Nigerian example: A vehicle, a bus, and a luxury bus are multilevel inheritance.

Table: Types of Inheritance

TypeDescriptionExample
SingleOne parent, one childAnimal → Dog
MultilevelParent → Child → GrandchildAnimal → Dog → Puppy
MultipleMany parents, one childFlyer + Swimmer → Duck

Illustration:

  Single:     Animal
                |
              Dog

  Multilevel: Animal
                |
              Dog
                |
              Puppy
  

Mini summary: There are different types of inheritance: single, multilevel, and multiple. Start with single inheritance.

Lesson 14: Common Mistakes with Inheritance

Definition: These are mistakes beginners often make.

Why it is important: Knowing them helps you avoid them.

Simple explanation: Here are some mistakes to watch out for.

List of mistakes:

  • Using inheritance when there is no “is-a” relationship.
  • Forgetting to call super().__init__().
  • Overriding a method and forgetting to use super() when needed.
  • Making the parent class too specific.
  • Creating too many levels of inheritance.

Illustration:

  Bad Inheritance          Good Inheritance
  +----------------+       +----------------+
  | Car IS-A Engine|       | Car IS-A Vehicle|
  | (wrong)        |       | (correct)      |
  +----------------+       +----------------+
  

Mini summary: Avoid common mistakes. Use inheritance only for “is-a”. Always call super().__init__().

Lesson 15: Putting It All Together – A Complete Program

Definition: You will now combine inheritance and polymorphism in one program.

Why it is important: This is how real OOP programs work.

Simple explanation: Create a parent class. Create child classes. Override methods. Use a loop to call the same method on all objects.

Real-life example: A zoo program with different animals.

School example: A school program with different types of students.

Home example: A smart home program with different appliances.

Nigerian example: A market program with different types of traders.

Example code:

  class Animal:
      def __init__(self, name):
          self.name = name

      def speak(self):
          print(self.name + " makes a sound.")

      def eat(self):
          print(self.name + " is eating.")

  class Dog(Animal):
      def speak(self):
          print(self.name + " barks.")

  class Cat(Animal):
      def speak(self):
          print(self.name + " meows.")

  class Cow(Animal):
      def speak(self):
          print(self.name + " moos.")

  animals = [Dog("Bingo"), Cat("Fluffy"), Cow("Buttercup")]

  for animal in animals:
      animal.eat()
      animal.speak()
      print("---")
  

Output:

  Bingo is eating.
  Bingo barks.
  ---
  Fluffy is eating.
  Fluffy meows.
  ---
  Buttercup is eating.
  Buttercup moos.
  ---
  

Illustration:

  Animal (parent)
      |
      V
  +--------+ +--------+ +--------+
  | Dog    | | Cat    | | Cow    |
  | speak  | | speak  | | speak  |
  | barks  | | meows  | | moos   |
  +--------+ +--------+ +--------+
  All inherit eat() from Animal
  

Mini summary: You can combine inheritance and polymorphism. One parent class, many child classes, and one loop to call them all.

📖 Key Vocabulary

WordSimple Definition
InheritanceWhen one class gets the data and actions of another class.
Parent classThe class being inherited from.
Child classThe class that inherits.
OverrideChanging a method in the child class.
super()A function that calls the parent’s method.
Polymorphism“Many forms” – different objects respond to the same action differently.
Is-a relationshipWhen a child “is a” type of parent.
Has-a relationshipWhen a class “has a” thing as an attribute.
Single inheritanceOne parent, one child.
Multilevel inheritanceParent → Child → Grandchild.
Multiple inheritanceMany parents, one child.
ReuseUsing code again.

🔑 Important Concepts

  • Inheritance saves time: Write common code once.
  • Parent and child: Child inherits from parent.
  • Is-a relationship: Use inheritance when child “is a” parent.
  • Override: Child can change a parent’s method.
  • super(): Call the parent’s method.
  • Polymorphism: Same action, different results.
  • Inheritance + polymorphism: Powerful together.
  • Use inheritance wisely: Only for “is-a” relationships.

🧭 Step-by-Step Explanations

How to create a parent class

  1. Write class ParentName:.
  2. Add __init__ with common attributes.
  3. Add common methods.

How to create a child class

  1. Write class ChildName(ParentName):.
  2. Add new attributes and methods.
  3. Override methods if needed.
  4. Use super() to call parent methods.

How to use polymorphism

  1. Create objects of different child classes.
  2. Put them in a list.
  3. Loop through the list.
  4. Call the same method on each object.

🌍 Real-life Examples

  • A vehicle parent class with car, bus, and bike children.
  • An animal parent class with dog, cat, and cow children.
  • A person parent class with student and teacher children.
  • An appliance parent class with fridge, fan, and cooker children.
  • A shape parent class with circle, square, and triangle children.

🇳🇬 Nigerian Examples

  • A trader parent class with food, cloth, and phone trader children.
  • A vehicle parent class with danfo, keke, and okada children.
  • A student parent class with science, art, and commercial children.
  • A market stall parent class with vegetable, meat, and fish children.
  • A bank account parent class with savings and current children.

🎈 Fun Examples Children Can Relate To

  • A video game character parent with hero, enemy, and boss children.
  • A toy parent class with car, doll, and ball children.
  • A pet parent class with dog, cat, and parrot children.
  • A food parent class with rice, beans, and yam children.
  • A sport parent class with football, basketball, and tennis children.

🏠 Everyday Examples

  • A phone parent class with basic phone and smartphone children.
  • A bag parent class with school bag, handbag, and shopping bag children.
  • A shoe parent class with sandal, sneaker, and boot children.
  • A drink parent class with water, juice, and tea children.
  • A furniture parent class with chair, table, and bed children.

👨‍👩‍👧 Parent Tips

  • Encourage your child to see inheritance in everyday life.
  • Ask them to explain the “is-a” relationship.
  • Help them create a simple parent and child class.
  • Celebrate when they make polymorphism work.
  • Remind them that inheritance saves time.

💡 Interesting Facts

  • Inheritance was invented in the 1960s.
  • It is one of the four pillars of OOP.
  • Python supports multiple inheritance.
  • Java does not support multiple inheritance with classes.
  • Polymorphism comes from Greek words meaning “many forms”.

🤔 Did You Know?

  • Did you know that a child class can have its own child class?
  • Did you know that super() can call any method, not just __init__?
  • Did you know that polymorphism works with functions too?
  • Did you know that you can check if an object is an instance of a class?
  • Did you know that inheritance can make code easier to fix?

📌 Remember This

  • Inheritance lets one class get data and methods from another.
  • Parent class is inherited from. Child class inherits.
  • Use inheritance for “is-a” relationships.
  • Override means changing a method in the child.
  • super() calls the parent’s method.
  • Polymorphism means “many forms”.
  • Same action, different results.
  • Inheritance and polymorphism work together.

⚠️ Common Mistakes

  • Using inheritance when there is no “is-a” relationship.
  • Forgetting to call super().__init__().
  • Overriding a method and forgetting to use super() when needed.
  • Making the parent class too specific.
  • Creating too many levels of inheritance.

✅ Best Practices

  • Use inheritance only for “is-a” relationships.
  • Always call super().__init__() in the child.
  • Keep the parent class general.
  • Use clear names for classes.
  • Test your code often.
  • Keep inheritance simple.

📊 Illustrations, Diagrams, and Tables

Flowchart: Inheritance and Polymorphism

  Create Parent Class
        |
        V
  Create Child Classes
        |
        V
  Override Methods
        |
        V
  Create Objects
        |
        V
  Loop and Call Same Method
        |
        V
  Polymorphism! 🎉
  

Timeline: Your OOP Journey

  Module 1: What is OOP?
  Module 2: Classes and Objects
  Module 3: Inheritance and Polymorphism
  Module 4: Encapsulation and Abstraction
  Module 5: Putting It All Together
  

Table: Parent vs Child Class

FeatureParent ClassChild Class
Also calledBase classDerived class
What it hasCommon attributes and methodsCommon + special attributes and methods
ExampleAnimalDog
Inherits fromNothingParent

Comparison Table: Inheritance vs Polymorphism

FeatureInheritancePolymorphism
What it doesReuses codeMany forms
RelationshipIs-aSame action, different results
ExampleDog inherits AnimalDog barks, Cat meows
Key wordclass Dog(Animal):Same method name

📝 Summary After Every Lesson

Lesson 1: Inheritance lets one class get the data and actions of another class.

Lesson 2: A parent class is inherited from. A child class inherits.

Lesson 3: Inheritance creates an “is-a” relationship.

Lesson 4: A parent class holds common attributes and methods.

Lesson 5: A child class inherits by writing the parent’s name in parentheses.

Lesson 6: Child classes can add new methods.

Lesson 7: Overriding means changing a method in the child class.

Lesson 8: super() calls the parent’s method.

Lesson 9: Polymorphism means “many forms”.

Lesson 10: Polymorphism lets you call the same method on different objects.

Lesson 11: Inheritance and polymorphism work together.

Lesson 12: Use inheritance for “is-a” relationships.

Lesson 13: There are different types of inheritance: single, multilevel, and multiple.

Lesson 14: Avoid common mistakes. Use inheritance wisely.

Lesson 15: You can combine inheritance and polymorphism in one program.

📦 End-of-Module Summary

In this module, you learned about inheritance and polymorphism. You learned that inheritance lets one class get the data and methods of another class. You learned about parent classes and child classes. You learned about the “is-a” relationship. You learned how to create a parent class and a child class. You learned how to add new methods and override existing ones. You learned how to use super() to call the parent’s method. You learned what polymorphism is and how it lets different objects respond to the same action in their own way. You also learned when to use inheritance and how to avoid common mistakes. You are now ready for Module Four, where you will learn about encapsulation and abstraction.

❓ Frequently Asked Questions (10 questions)

  1. What is inheritance? When one class gets the data and actions of another class.
  2. What is a parent class? The class being inherited from.
  3. What is a child class? The class that inherits.
  4. What is the “is-a” relationship? When a child “is a” type of parent.
  5. How do I create a child class? Write class Child(Parent):.
  6. What is overriding? Changing a method in the child class.
  7. What is super()? A function that calls the parent’s method.
  8. What is polymorphism? “Many forms” – different objects respond to the same action differently.
  9. When should I use inheritance? When there is an “is-a” relationship.
  10. What are common mistakes? Using inheritance wrongly, forgetting super().

🔗 Matching Exercises

Match the word to its meaning.

WordMeaning
1. InheritanceA. Changing a method in the child class
2. Parent classB. When one class gets data and actions from another
3. Child classC. The class being inherited from
4. OverrideD. The class that inherits
5. PolymorphismE. “Many forms”

Answers: 1-B, 2-C, 3-D, 4-A, 5-E

🧩 Scenario-based Exercises

  1. You have a class Animal. You want to create a class Dog that inherits from it. How do you write it? (class Dog(Animal):)
  2. You want Dog to have a bark() method. Where do you add it? (In the Dog class)
  3. You want Dog to speak differently from Animal. What do you do? (Override the speak() method)
  4. You want to call the parent’s __init__ from the child. What do you use? (super().__init__())
  5. You have a list of different animals. You want each to speak. What do you do? (Loop and call speak())

👥 Group Activity

Title: Build a Family of Classes

Instructions: In groups of 3, choose a parent class (e.g., Vehicle, Animal, Person). Create two child classes. Add at least one new method and override one method. Create objects and call the methods. Present to the class.

🧑 Individual Activity

Title: My First Inheritance

Instructions: Write a parent class called Shape with a method area(). Create two child classes: Circle and Square. Override area() in each. Create objects and call area(). Write down what happens.

🛠️ Mini Project

Title: A Zoo Program

Instructions: Create a parent class Animal with name and age. Create child classes Dog, Cat, and Cow. Override speak() in each. Create a list of animals. Loop through the list and call speak() and eat(). Print the results.

📋 Practical Assignment

Task: Write a short paragraph (5 sentences) explaining what you learned about inheritance and polymorphism. Then, list three things you found easy and one thing you found hard. Finally, describe the parent class and child classes you created.

🔑 Key Takeaways

  • Inheritance lets one class get data and methods from another.
  • Parent class is inherited from. Child class inherits.
  • Use inheritance for “is-a” relationships.
  • Override means changing a method in the child.
  • super() calls the parent’s method.
  • Polymorphism means “many forms”.
  • Same action, different results.
  • Inheritance and polymorphism work together.
  • Use inheritance wisely.

💬 Classroom Discussion Questions

  1. Why is inheritance useful?
  2. What is the difference between a parent class and a child class?
  3. What does “is-a” relationship mean?
  4. How does polymorphism make programs flexible?
  5. What would you build with inheritance and polymorphism?

➡️ Preparation for the Next Module

In Module Four, we will learn about encapsulation and abstraction. You will learn how to hide data and show only what is needed. You will learn how to protect your objects. To get ready, make sure you:

  • Understand inheritance and polymorphism.
  • Know how to create parent and child classes.
  • Know how to override methods.
  • Have practised writing your own inheritance examples.

See you in Module Four! 🚀


End of Module Three · Object Oriented Programming

🏆 Get Certified

🔒

Earn this certificate

Every lesson is already free to read. Sign up, finish the lessons, pass the exam (₦2,000 or 20,000 coins), and get a verified certificate with your name on it.

🎓 Sign Up to Get Certified
🛠️ Practice Tools
Hands-on simulators & labs - subscription required.
→
🎯 Internship Tasks
Real-world tasks to build your portfolio - unlock them with a subscription.
→