Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1088613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:05:38+00:00 2026-05-16T23:05:38+00:00

Can anyone please give me a real life, practical example of Polymorphism? My professor

  • 0

Can anyone please give me a real life, practical example of Polymorphism? My professor tells me the same old story I have heard always about the + operator. a+b = c and 2+2 = 4, so this is polymorphism. I really can’t associate myself with such a definition, since I have read and re-read this in many books.

What I need is a real world example with code, something that I can truly associate with.

For example, here is a small example, just in case you want to extend it.

>>> class Person(object):
    def __init__(self, name):
        self.name = name

>>> class Student(Person):
    def __init__(self, name, age):
        super(Student, self).__init__(name)
        self.age = age
  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:05:39+00:00Added an answer on May 16, 2026 at 11:05 pm

    Check the Wikipedia example: it is very helpful at a high level:

    class Animal:
        def __init__(self, name):    # Constructor of the class
            self.name = name
        def talk(self):              # Abstract method, defined by convention only
            raise NotImplementedError("Subclass must implement abstract method")
    
    class Cat(Animal):
        def talk(self):
            return 'Meow!'
    
    class Dog(Animal):
        def talk(self):
            return 'Woof! Woof!'
    
    animals = [Cat('Missy'),
               Cat('Mr. Mistoffelees'),
               Dog('Lassie')]
    
    for animal in animals:
        print animal.name + ': ' + animal.talk()
    
    # prints the following:
    #
    # Missy: Meow!
    # Mr. Mistoffelees: Meow!
    # Lassie: Woof! Woof!
    

    Notice the following: all animals “talk”, but they talk differently. The “talk” behaviour is thus polymorphic in the sense that it is realized differently depending on the animal. So, the abstract “animal” concept does not actually “talk”, but specific animals (like dogs and cats) have a concrete implementation of the action “talk”.

    Similarly, the “add” operation is defined in many mathematical entities, but in particular cases you “add” according to specific rules: 1+1 = 2, but (1+2i)+(2-9i)=(3-7i).

    Polymorphic behaviour allows you to specify common methods in an “abstract” level, and implement them in particular instances.

    For your example:

    class Person(object):
        def pay_bill(self):
            raise NotImplementedError
    
    class Millionare(Person):
        def pay_bill(self):
            print "Here you go! Keep the change!"
    
    class GradStudent(Person):
        def pay_bill(self):
            print "Can I owe you ten bucks or do the dishes?"
    

    You see, millionares and grad students are both persons. But when it comes to paying a bill, their specific “pay the bill” action is different.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone please give me any example of situation in a database-driven application where
Can anyone please give an example how to use the OnExited event in C++,
Can anyone please give me a simple example of how to add elements to
It does not matter what programming language. Can anyone please give me an idea
Can anyone please give me some tutorial URL for freeswitch? I am a beginner
Can anyone please give me code or links or concept for running an android
I want to know about unmanaged resources. Can anyone please give me a basic
Can anyone please provide me with an example that can help me to understand
can anyone please give me a simple code to do this: a user purchases
Can anyone please give me a tip or guide on how to create a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.