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 pillars of OOP?" is:
Abstraction
Encapsulation
Inheritance
Polymorphism
What I fail to understand is how inheritance not contained in polymorphism?
in other words, how can polymorphism be used without the use of inheritance?
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 inheritance A* a = new A(); a->foo();//prints A a->bar();//prints A, obviously As I see it, polymorphism brings with it inheritance.
Please explain why it is distinct - or why can't inheritance be discarded as a key pillar of its own. We could use polymorphism or not.