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
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; 11-26-2019 at 12:20 AM.
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.
What is polymorphism in example
each function are the same but give different resultCode:#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; }
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.