{"id":8655,"date":"2021-09-02T13:16:06","date_gmt":"2021-09-02T13:16:06","guid":{"rendered":"https:\/\/www.scmgalaxy.com\/tutorials\/?p=8655"},"modified":"2021-09-02T13:16:07","modified_gmt":"2021-09-02T13:16:07","slug":"tutorial-for-polymorphism-in-oops","status":"publish","type":"post","link":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-polymorphism-in-oops\/","title":{"rendered":"Tutorial for Polymorphism in OOPS"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">What is\u00a0<strong>Polymorphism<\/strong>?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Polymorphism, as its name implies, comes in a variety of forms. OOP allows for the use of a variety of techniques I. Simply expressed, they have to do with how methods are used, and how different methods operate for different objects. Method Overriding and Method Overloading are two ways that polymorphic methods allow for different actions to be done.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>The benefits of Polymorphism are:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Objects of different types can be passed through the same interface<\/li><li>Method overriding<\/li><li>Method overloading<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Method Overriding<\/strong>:- Overriding is used in the polymorphism of runtime. By overriding a parent class&#8217;s method, a child class can implement a different method. In the case of our dogs, we may prefer a specific type of bark that is distinct from the generic type of dog (<code><span class=\"has-inline-color has-vivid-red-color\">TrackingDog<\/span><\/code>).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example:-<\/strong><\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/AdarshAshwani\/2f14c51fb9288cff503e2f683a4a540b.js\"><\/script>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-61.png\" alt=\"\" width=\"443\" height=\"369\"\/><figcaption>TrackingDog\u2019s overriding the bark() method<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Method Overloading<\/strong>:- Overloading is used at the polymorphic build time. Although methods and functions may have the same name, the call method has its own set of arguments. Different results may be obtained depending on the number of parameters entered.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example<\/strong>:- There are no parameters supplied to the <code><span class=\"has-inline-color has-vivid-red-color\">updateAttendance()<\/span><\/code> method. The count will be added one day. When the <code><span class=\"has-inline-color has-vivid-red-color\">updateAttendance(4)<\/span><\/code> argument is used, the x <code><span class=\"has-inline-color has-vivid-red-color\">xupdateAttendance(x)<\/span><\/code> parameter is used, and four days are added to the total.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/AdarshAshwani\/5a4dc586be245a338a81b7127ea425c9.js\"><\/script>\n","protected":false},"excerpt":{"rendered":"<p>What is\u00a0Polymorphism? Polymorphism, as its name implies, comes in a variety of forms. OOP allows for the use of a [&hellip;]<\/p>\n","protected":false},"author":33,"featured_media":8664,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[16,5388],"tags":[6678,5095,5136,177,6673,6674,6677,213,6675,6676],"class_list":["post-8655","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","category-php","tag-benefits-of-polymorphism","tag-javascript","tag-oops","tag-php","tag-polymorphism","tag-polymorphism-in-oops","tag-the-benefits-of-polymorphism-are","tag-tutorial","tag-tutorial-for-polymorphism-in-oops","tag-what-is-polymorphism"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Tutorial for Polymorphism in OOPS - scmGalaxy<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-polymorphism-in-oops\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Tutorial for Polymorphism in OOPS - scmGalaxy\" \/>\n<meta property=\"og:description\" content=\"What is\u00a0Polymorphism? Polymorphism, as its name implies, comes in a variety of forms. OOP allows for the use of a [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-polymorphism-in-oops\/\" \/>\n<meta property=\"og:site_name\" content=\"scmGalaxy\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/profile.php?id=100003935402658\" \/>\n<meta property=\"article:published_time\" content=\"2021-09-02T13:16:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-09-02T13:16:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2021\/09\/Tutorial-for-Polymorphism-in-OOPS.png\" \/>\n\t<meta property=\"og:image:width\" content=\"703\" \/>\n\t<meta property=\"og:image:height\" content=\"214\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ashwani Kumar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ashwani Kumar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-polymorphism-in-oops\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-polymorphism-in-oops\\\/\"},\"author\":{\"name\":\"Ashwani Kumar\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/19f28f8f969c1679bfb37d4dad6adc31\"},\"headline\":\"Tutorial for Polymorphism in OOPS\",\"datePublished\":\"2021-09-02T13:16:06+00:00\",\"dateModified\":\"2021-09-02T13:16:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-polymorphism-in-oops\\\/\"},\"wordCount\":220,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-polymorphism-in-oops\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2021\\\/09\\\/Tutorial-for-Polymorphism-in-OOPS.png\",\"keywords\":[\"benefits of Polymorphism\",\"Javascript\",\"oops\",\"Php\",\"Polymorphism\",\"Polymorphism in OOPS\",\"The benefits of Polymorphism are:\",\"Tutorial\",\"Tutorial for Polymorphism in OOPS\",\"What is\u00a0Polymorphism\"],\"articleSection\":[\"JavaScript\",\"php\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-polymorphism-in-oops\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-polymorphism-in-oops\\\/\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-polymorphism-in-oops\\\/\",\"name\":\"Tutorial for Polymorphism in OOPS - scmGalaxy\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-polymorphism-in-oops\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-polymorphism-in-oops\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2021\\\/09\\\/Tutorial-for-Polymorphism-in-OOPS.png\",\"datePublished\":\"2021-09-02T13:16:06+00:00\",\"dateModified\":\"2021-09-02T13:16:07+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/19f28f8f969c1679bfb37d4dad6adc31\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-polymorphism-in-oops\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-polymorphism-in-oops\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-polymorphism-in-oops\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2021\\\/09\\\/Tutorial-for-Polymorphism-in-OOPS.png\",\"contentUrl\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2021\\\/09\\\/Tutorial-for-Polymorphism-in-OOPS.png\",\"width\":703,\"height\":214},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-polymorphism-in-oops\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tutorial for Polymorphism in OOPS\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\",\"name\":\"scmGalaxy\",\"description\":\"A Platform for Software Engineers\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/19f28f8f969c1679bfb37d4dad6adc31\",\"name\":\"Ashwani Kumar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b0fe597f4b8473400f95ce54bee0bdd62df08a319a198ad229b279aaab4f5410?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b0fe597f4b8473400f95ce54bee0bdd62df08a319a198ad229b279aaab4f5410?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b0fe597f4b8473400f95ce54bee0bdd62df08a319a198ad229b279aaab4f5410?s=96&d=mm&r=g\",\"caption\":\"Ashwani Kumar\"},\"description\":\"There is no end to education. It is not that you read a book, pass an examination, and finish with education. The whole of life, from the moment you are born to the moment you die, is a process of learning.\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/profile.php?id=100003935402658\",\"https:\\\/\\\/www.instagram.com\\\/adarshashwani\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/adarsh-ashwani-a75b23130\\\/\"],\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/author\\\/ashwani\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Tutorial for Polymorphism in OOPS - scmGalaxy","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-polymorphism-in-oops\/","og_locale":"en_US","og_type":"article","og_title":"Tutorial for Polymorphism in OOPS - scmGalaxy","og_description":"What is\u00a0Polymorphism? Polymorphism, as its name implies, comes in a variety of forms. OOP allows for the use of a [&hellip;]","og_url":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-polymorphism-in-oops\/","og_site_name":"scmGalaxy","article_author":"https:\/\/www.facebook.com\/profile.php?id=100003935402658","article_published_time":"2021-09-02T13:16:06+00:00","article_modified_time":"2021-09-02T13:16:07+00:00","og_image":[{"width":703,"height":214,"url":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2021\/09\/Tutorial-for-Polymorphism-in-OOPS.png","type":"image\/png"}],"author":"Ashwani Kumar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Ashwani Kumar","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-polymorphism-in-oops\/#article","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-polymorphism-in-oops\/"},"author":{"name":"Ashwani Kumar","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/19f28f8f969c1679bfb37d4dad6adc31"},"headline":"Tutorial for Polymorphism in OOPS","datePublished":"2021-09-02T13:16:06+00:00","dateModified":"2021-09-02T13:16:07+00:00","mainEntityOfPage":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-polymorphism-in-oops\/"},"wordCount":220,"commentCount":0,"image":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-polymorphism-in-oops\/#primaryimage"},"thumbnailUrl":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2021\/09\/Tutorial-for-Polymorphism-in-OOPS.png","keywords":["benefits of Polymorphism","Javascript","oops","Php","Polymorphism","Polymorphism in OOPS","The benefits of Polymorphism are:","Tutorial","Tutorial for Polymorphism in OOPS","What is\u00a0Polymorphism"],"articleSection":["JavaScript","php"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-polymorphism-in-oops\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-polymorphism-in-oops\/","url":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-polymorphism-in-oops\/","name":"Tutorial for Polymorphism in OOPS - scmGalaxy","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-polymorphism-in-oops\/#primaryimage"},"image":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-polymorphism-in-oops\/#primaryimage"},"thumbnailUrl":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2021\/09\/Tutorial-for-Polymorphism-in-OOPS.png","datePublished":"2021-09-02T13:16:06+00:00","dateModified":"2021-09-02T13:16:07+00:00","author":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/19f28f8f969c1679bfb37d4dad6adc31"},"breadcrumb":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-polymorphism-in-oops\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-polymorphism-in-oops\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-polymorphism-in-oops\/#primaryimage","url":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2021\/09\/Tutorial-for-Polymorphism-in-OOPS.png","contentUrl":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2021\/09\/Tutorial-for-Polymorphism-in-OOPS.png","width":703,"height":214},{"@type":"BreadcrumbList","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-polymorphism-in-oops\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.scmgalaxy.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Tutorial for Polymorphism in OOPS"}]},{"@type":"WebSite","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website","url":"https:\/\/www.scmgalaxy.com\/tutorials\/","name":"scmGalaxy","description":"A Platform for Software Engineers","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.scmgalaxy.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/19f28f8f969c1679bfb37d4dad6adc31","name":"Ashwani Kumar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b0fe597f4b8473400f95ce54bee0bdd62df08a319a198ad229b279aaab4f5410?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b0fe597f4b8473400f95ce54bee0bdd62df08a319a198ad229b279aaab4f5410?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b0fe597f4b8473400f95ce54bee0bdd62df08a319a198ad229b279aaab4f5410?s=96&d=mm&r=g","caption":"Ashwani Kumar"},"description":"There is no end to education. It is not that you read a book, pass an examination, and finish with education. The whole of life, from the moment you are born to the moment you die, is a process of learning.","sameAs":["https:\/\/www.facebook.com\/profile.php?id=100003935402658","https:\/\/www.instagram.com\/adarshashwani\/","https:\/\/www.linkedin.com\/in\/adarsh-ashwani-a75b23130\/"],"url":"https:\/\/www.scmgalaxy.com\/tutorials\/author\/ashwani\/"}]}},"_links":{"self":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/8655","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/users\/33"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/comments?post=8655"}],"version-history":[{"count":1,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/8655\/revisions"}],"predecessor-version":[{"id":8665,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/8655\/revisions\/8665"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/media\/8664"}],"wp:attachment":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/media?parent=8655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/categories?post=8655"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/tags?post=8655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}