inheritance - 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 correct answer in many job interviews - general correct answer question: "what 4 pillars of oop?" is:

  1. abstraction

  2. encapsulation

  3. inheritance

  4. polymorphism

what fail understand how inheritance not contained in polymorphism?

in other words, how can polymorphism used without use of inheritance?

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

as see it, polymorphism brings inheritance.

please explain why distinct - or why can't inheritance discarded key pillar of own. use polymorphism or not.

what fail understand how inheritence not contained in polymorphism?

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

there 3 main types of polymorphism, , 1 of them requires inheritance work.

  1. ad-hoc polymorphism: more commonly known function/method overloading, multiple functions can share same name have different signatures. whether or not return type part of signature language dependent.

  2. parametric polymorphism: in oop, more commonly known generics, function/method can work multiple concrete types, , return multiple concrete types, providing compile time safety.

  3. subtype polymorphism: 1 think people think of when talk polymorphism. know, when subtypes provide different implementation of parent functions/methods.

you can read more different types of polymorphism wikipedia article here: https://en.wikipedia.org/wiki/polymorphism_(computer_science)


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -