Thread: difference between Inheritance and polymorphism?

  1. #1
    Registered User
    Join Date
    Oct 2019
    Posts
    34

    difference between Inheritance and polymorphism?

    Hi,

    Inheritance is theprocess of creating a new Class from the existing class without modifying it

    The term polymorphism is rather confusing Can anybody help me in understanding the main difference between Inheritance and polymorphism?

    Thanks
    Last edited by gajya; 1 Week Ago at 12:20 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,529
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2019
    Posts
    34
    What is polymorphism in example

    Code:
    #include <iostream>  
    using namespace std; 
     
    class Fruits { 
     
        public: 
     
    void taste(){   
     
    cout<<"Juicy...";   
     
        }     
     
    };  
     
    class Apple: public Fruits   
     
    {   
     
     public: 
     
     void taste()   
     
        {   
     
           cout<<"Juicy Apple...";   
     
        }   
     
    }; 
     
    int main(void) { 
     
       Apple a = Apple();   
     
       a.taste(); 
     
       return 0; 
     
    }
    each function are the same but give different result

  4. #4
    Registered User
    Join Date
    Aug 2019
    Location
    Inside a Singularity
    Posts
    169
    Polymorphism is essentially the ability of one thing to mean several different things based upon usage. You implement it through function overloading, operator overloading, method overriding and virtual functions, etc.

    Inheritance is the ability to derive/share properties of one/different thing(s) with other/different thing(s).

    The time you take to come on here and ask a question should be invested in Google searches. These are basic features that can get really complicated really fast. There are a tonne of good sources that teach you some (if not all) of the basics with source code provided too. Consider buying a reference book if it's really that hard to grasp the concepts and if not, consider studying another branch if it's really that hard to google things up. When you don't find an answer to your problem, ask questions. Reference Books and using Google will be your best friends.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need some help with inheritance and polymorphism
    By Absurd in forum C++ Programming
    Replies: 5
    Last Post: 06-21-2013, 02:00 PM
  2. inheritance or polymorphism
    By asysyah in forum C++ Programming
    Replies: 4
    Last Post: 10-26-2010, 11:22 AM
  3. polymorphism and inheritance
    By stewie griffin in forum C++ Programming
    Replies: 12
    Last Post: 01-16-2009, 02:45 AM
  4. Inheritance and Polymorphism
    By bench386 in forum C++ Programming
    Replies: 2
    Last Post: 03-18-2004, 10:19 PM
  5. inheritance and polymorphism uses...
    By tetra in forum C++ Programming
    Replies: 5
    Last Post: 05-06-2003, 05:30 PM

Tags for this Thread