As stated here
https://standardofnorms.wordpress.com/2012/09/02/4-pillars-of-object-oriented-programming/
and as the correct answer in many job interviews - the general correct answer for the question: "What are the 4 pollarspillars of OOP?" is:
Abstraction
Encapsulation
Inheritance
Polymorphism
What I fail to understand is how inheritenceinheritance not contained in polymorphism?
in other words, how can polymorphism be used without the use of inheritenceinheritance?
The only way I know of using polymorphism is
class A{ virtual void foo(){cout<<"A";} void bar(){cout<<"A";} }; class B : public A{ virtual foo(){cout<<"B";} }; A* ab = new B(); ab->foo();//prints B, using polymorphism ab->bar();//prints A, using inheritenceinheritance A* a = new A(); a->foo();//prints A a->bar();//prints A, obviously As I see it, polymorphism brings with it inheritenceinheritance.
Please explain why it is distinct - or why can't inheritenceinheritance be discarded as a key pillar of its own. We could use polymorphism or not.