Learn with Yasir

Share Your Feedback

Task: Design and Implementation of a Dog Class Using Object-Oriented Programming in Python


Task: Design and Implementation of a Dog Class Using Object-Oriented Programming in Python

📌 Problem Statement

You are required to demonstrate the concept of Object-Oriented Programming (OOP) in Python by creating a simple class that models real-world objects.

Design a class named Dog that represents different dogs with shared and individual characteristics.

Each dog has a common species and unique attributes such as name and breed. The class should also define behavior that allows a dog to bark.


🎯 Task Requirements

🔹 1. Class Design

Create a class Dog with the following:

  • A class attribute:

    • species = "Canine" (common for all dogs)
  • Instance attributes (defined using constructor):

    • name
    • breed

🔹 2. Constructor

Implement a constructor __init__() that initializes:

  • Dog’s name
  • Dog’s breed

🔹 3. Method Implementation

Define a method:

  • bark() → This method should print a message in the format:

    <name> says Woof!
    

🔹 4. Object Creation

Create at least two objects of the Dog class:

  • Dog 1: Buddy, Labrador
  • Dog 2: Max, Beagle

🔹 5. Method Execution

Call the bark() method for at least one object and observe the output.


🧪 Expected Output

Buddy says Woof!

Task #2: Creating a Student Class with Constructor and Object Methods

Write the Python code to define a class named Student with a constructor that initializes three attributes: name, age, and grade. Add a method named info() that prints the student’s details. Create two objects: • student1 with name “Hamza”, age 8, grade 3 • student2 with name “Muhammad”, age 15, grade 10 Print the name of the first student and call the info() method for both objects.