{"id":8623,"date":"2021-09-01T13:13:35","date_gmt":"2021-09-01T13:13:35","guid":{"rendered":"https:\/\/www.scmgalaxy.com\/tutorials\/?p=8623"},"modified":"2021-09-01T13:13:37","modified_gmt":"2021-09-01T13:13:37","slug":"tutorial-for-inheritance-in-oops","status":"publish","type":"post","link":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-inheritance-in-oops\/","title":{"rendered":"Tutorial for Inheritance in OOPS"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">what is\u00a0<strong>Inheritance<\/strong>?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In OOP, the concept of inheritance allows a class to accept or have the properties of another class (inherited). A sub-class or derived class is a class that inherits the characteristics\/methods of another class. Heritage reduces code redundancy, allowing the class to use other class methods without having to rewrite the code. This allows for dynamic programming using the main class&#8217;s methods (also called the parent class). A subclass has the same properties as a primary class, but it can also have additional methods that are either completely independent or not present in the main class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>What is the Function of Inheritance?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Children&#8217;s classes may be built to enhance the parent&#8217;s class functionality and add more characteristics once essential properties and behaviors have been defined in the parent&#8217;s class.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example:-<\/strong> <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This distinction is demonstrated by creating a parent class child class(HerdingDog) (Dog) and then adding a single herd() behaviour.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The following code shows how the child class (HerdingDog) inherits a parent class method (bark) (Dog), and the child class adds an extra method herd().<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/AdarshAshwani\/56dd53858a250d518c8102194f9489c4.js\"><\/script>\n\n\n\n<p class=\"wp-block-paragraph\">When the code uses the fluffy.bark() function, the method bark() travels up the child&#8217;s chain to find out where the bark method is declared.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/AdarshAshwani\/1b76d5c5645ed236d281b5d1af95eb7e.js\"><\/script>\n","protected":false},"excerpt":{"rendered":"<p>what is\u00a0Inheritance? In OOP, the concept of inheritance allows a class to accept or have the properties of another class [&hellip;]<\/p>\n","protected":false},"author":33,"featured_media":8625,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5388],"tags":[6657,6658,6640,5136,177,6298,6655,6656],"class_list":["post-8623","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-function-of-inheritance","tag-inheritance","tag-object-oriented-programming","tag-oops","tag-php","tag-php-tutorial","tag-what-is-inheritance","tag-what-is-the-function-of-inheritance"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Tutorial for Inheritance 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-inheritance-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 Inheritance in OOPS - scmGalaxy\" \/>\n<meta property=\"og:description\" content=\"what is\u00a0Inheritance? In OOP, the concept of inheritance allows a class to accept or have the properties of another class [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-inheritance-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-01T13:13:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-09-01T13:13:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2021\/09\/Inheritance.png\" \/>\n\t<meta property=\"og:image:width\" content=\"750\" \/>\n\t<meta property=\"og:image:height\" content=\"398\" \/>\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=\"1 minute\" \/>\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-inheritance-in-oops\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-inheritance-in-oops\\\/\"},\"author\":{\"name\":\"Ashwani Kumar\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/19f28f8f969c1679bfb37d4dad6adc31\"},\"headline\":\"Tutorial for Inheritance in OOPS\",\"datePublished\":\"2021-09-01T13:13:35+00:00\",\"dateModified\":\"2021-09-01T13:13:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-inheritance-in-oops\\\/\"},\"wordCount\":215,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-inheritance-in-oops\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2021\\\/09\\\/Inheritance.png\",\"keywords\":[\"Function of Inheritance\",\"Inheritance\",\"Object-oriented programming\",\"oops\",\"Php\",\"php tutorial\",\"what is\u00a0Inheritance\",\"What is the Function of Inheritance\"],\"articleSection\":[\"php\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-inheritance-in-oops\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-inheritance-in-oops\\\/\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-inheritance-in-oops\\\/\",\"name\":\"Tutorial for Inheritance in OOPS - scmGalaxy\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-inheritance-in-oops\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-inheritance-in-oops\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2021\\\/09\\\/Inheritance.png\",\"datePublished\":\"2021-09-01T13:13:35+00:00\",\"dateModified\":\"2021-09-01T13:13:37+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/19f28f8f969c1679bfb37d4dad6adc31\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-inheritance-in-oops\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-inheritance-in-oops\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-inheritance-in-oops\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2021\\\/09\\\/Inheritance.png\",\"contentUrl\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2021\\\/09\\\/Inheritance.png\",\"width\":750,\"height\":398},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/tutorial-for-inheritance-in-oops\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tutorial for Inheritance 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 Inheritance 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-inheritance-in-oops\/","og_locale":"en_US","og_type":"article","og_title":"Tutorial for Inheritance in OOPS - scmGalaxy","og_description":"what is\u00a0Inheritance? In OOP, the concept of inheritance allows a class to accept or have the properties of another class [&hellip;]","og_url":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-inheritance-in-oops\/","og_site_name":"scmGalaxy","article_author":"https:\/\/www.facebook.com\/profile.php?id=100003935402658","article_published_time":"2021-09-01T13:13:35+00:00","article_modified_time":"2021-09-01T13:13:37+00:00","og_image":[{"width":750,"height":398,"url":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2021\/09\/Inheritance.png","type":"image\/png"}],"author":"Ashwani Kumar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Ashwani Kumar","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-inheritance-in-oops\/#article","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-inheritance-in-oops\/"},"author":{"name":"Ashwani Kumar","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/19f28f8f969c1679bfb37d4dad6adc31"},"headline":"Tutorial for Inheritance in OOPS","datePublished":"2021-09-01T13:13:35+00:00","dateModified":"2021-09-01T13:13:37+00:00","mainEntityOfPage":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-inheritance-in-oops\/"},"wordCount":215,"commentCount":0,"image":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-inheritance-in-oops\/#primaryimage"},"thumbnailUrl":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2021\/09\/Inheritance.png","keywords":["Function of Inheritance","Inheritance","Object-oriented programming","oops","Php","php tutorial","what is\u00a0Inheritance","What is the Function of Inheritance"],"articleSection":["php"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-inheritance-in-oops\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-inheritance-in-oops\/","url":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-inheritance-in-oops\/","name":"Tutorial for Inheritance in OOPS - scmGalaxy","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-inheritance-in-oops\/#primaryimage"},"image":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-inheritance-in-oops\/#primaryimage"},"thumbnailUrl":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2021\/09\/Inheritance.png","datePublished":"2021-09-01T13:13:35+00:00","dateModified":"2021-09-01T13:13:37+00:00","author":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/19f28f8f969c1679bfb37d4dad6adc31"},"breadcrumb":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-inheritance-in-oops\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-inheritance-in-oops\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-inheritance-in-oops\/#primaryimage","url":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2021\/09\/Inheritance.png","contentUrl":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2021\/09\/Inheritance.png","width":750,"height":398},{"@type":"BreadcrumbList","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/tutorial-for-inheritance-in-oops\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.scmgalaxy.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Tutorial for Inheritance 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\/8623","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=8623"}],"version-history":[{"count":1,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/8623\/revisions"}],"predecessor-version":[{"id":8626,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/8623\/revisions\/8626"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/media\/8625"}],"wp:attachment":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/media?parent=8623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/categories?post=8623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/tags?post=8623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}