Skip to main content

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:

  1. Abstraction

  2. Encapsulation

  3. Inheritance

  4. 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.

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 pollars of OOP?" is:

  1. Abstraction

  2. Encapsulation

  3. Inheritance

  4. Polymorphism

What I fail to understand is how inheritence not contained in polymorphism?

in other words, how can polymorphism be used without the use of inheritence?

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 inheritence A* a = new A(); a->foo();//prints A a->bar();//prints A, obviously 

As I see it, polymorphism brings with it inheritence.

Please explain why it is distinct - or why can't inheritence be discarded as a key pillar of its own. We could use polymorphism or not.

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:

  1. Abstraction

  2. Encapsulation

  3. Inheritance

  4. 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.

Source Link
Gulzar
  • 28.8k
  • 42
  • 159
  • 260

polymorphism vs inheritence as the pillars of oop

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 pollars of OOP?" is:

  1. Abstraction

  2. Encapsulation

  3. Inheritance

  4. Polymorphism

What I fail to understand is how inheritence not contained in polymorphism?

in other words, how can polymorphism be used without the use of inheritence?

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 inheritence A* a = new A(); a->foo();//prints A a->bar();//prints A, obviously 

As I see it, polymorphism brings with it inheritence.

Please explain why it is distinct - or why can't inheritence be discarded as a key pillar of its own. We could use polymorphism or not.