Skip to content

Kimonyiphillip/oop_assignment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ Object-Oriented Programming Assignment

Overview

This assignment demonstrates the principles of Object-Oriented Programming (OOP) in Python through two activities:

  1. Class Design with Inheritance ๐Ÿ—๏ธ
  2. Polymorphism Challenge ๐ŸŽญ

The goal is to understand how to design classes, use constructors, apply inheritance, and implement polymorphism in real-world examples.


Activity 1: Design Your Own Class

Task:

  • Create a class representing something of your choice (Smartphone, Book, Superhero, etc.).
  • Add attributes and methods to bring it to life.
  • Use a constructor __init__() to initialize values.
  • Implement inheritance to show how one class can extend another.

Example:

class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age
    
    def introduce(self):
        return f"Hi, I'm {self.name}, and I'm {self.age} years old."

class Superhero(Person):
    def __init__(self, name, age, power):
        super().__init__(name, age)
        self.power = power
    
    def use_power(self):
        return f"{self.name} uses {self.power}! "

hero = Superhero("Spider-Man", 18, "Web Shooting")
print(hero.introduce())
print(hero.use_power())

About

polymorphism and classes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages