{"id":112,"date":"2026-03-02T08:42:37","date_gmt":"2026-03-02T03:42:37","guid":{"rendered":"https:\/\/gigz.pk\/python\/?post_type=lesson&#038;p=112"},"modified":"2026-03-16T09:25:09","modified_gmt":"2026-03-16T04:25:09","slug":"method-overriding","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/python\/lesson\/method-overriding\/","title":{"rendered":"Method Overriding"},"content":{"rendered":"\n<p>Method Overriding is a feature of Inheritance in Object-Oriented Programming (OOP).<\/p>\n\n\n\n<p>It allows a child class to provide a specific implementation of a method that is already defined in its parent class.<\/p>\n\n\n\n<p>In simple words:<br>The child class changes the behavior of a parent class method.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Why Use Method Overriding?<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To modify or extend parent behavior<\/li>\n\n\n\n<li>To implement runtime polymorphism<\/li>\n\n\n\n<li>To customize functionality in child classes<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Basic Example<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">class Animal:<br>    def sound(self):<br>        print(\"Animal makes a sound\")class Dog(Animal):<br>    def sound(self):<br>        print(\"Dog barks\")d = Dog()<br>d.sound()<\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Dog barks<\/pre>\n\n\n\n<p>Here:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Dog<\/code> inherits from <code>Animal<\/code><\/li>\n\n\n\n<li>The <code>sound()<\/code> method in <code>Dog<\/code> overrides the parent method<\/li>\n\n\n\n<li>The child version runs instead of the parent version<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Using super() in Method Overriding<\/strong><\/h2>\n\n\n\n<p>Sometimes we want to use the parent method along with the child method.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class Animal:<br>    def sound(self):<br>        print(\"Animal makes a sound\")class Dog(Animal):<br>    def sound(self):<br>        super().sound()<br>        print(\"Dog barks\")d = Dog()<br>d.sound()<\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Animal makes a sound<br>Dog barks<\/pre>\n\n\n\n<p><code>super()<\/code> calls the parent class method.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Rules of Method Overriding<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Method name must be the same<\/li>\n\n\n\n<li>Parameters should be the same<\/li>\n\n\n\n<li>Must use inheritance<\/li>\n\n\n\n<li>Happens at runtime<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Example with Constructor Overriding<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">class Person:<br>    def __init__(self):<br>        print(\"Person Constructor\")class Student(Person):<br>    def __init__(self):<br>        print(\"Student Constructor\")s = Student()<\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Student Constructor<\/pre>\n\n\n\n<p>The child constructor overrides the parent constructor.<\/p>\n\n\n\n<p>To call parent constructor:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class Student(Person):<br>    def __init__(self):<br>        super().__init__()<br>        print(\"Student Constructor\")<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Method Overriding vs Method Overloading<\/strong><\/h2>\n\n\n\n<p>Method Overriding<br>Same method name<br>Same parameters<br>Different implementation in child class<br>Requires inheritance<\/p>\n\n\n\n<p>Method Overloading<br>Same method name<br>Different parameters<br>Python supports it using default arguments<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Key Takeaway<\/strong><\/h2>\n\n\n\n<p>Method Overriding allows a child class to redefine a parent class method.<\/p>\n\n\n\n<p>It supports runtime polymorphism and makes OOP programs flexible and extensible.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/python\/\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">OBJECT ORIENTED PROGRAMMING IN PYTHON (OOP) > OOP Concepts > Method Overriding<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1773634712319\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<p><\/p>\n","protected":false},"menu_order":55,"template":"","class_list":["post-112","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Method Overriding - One Language. Endless Possibilities<\/title>\n<meta name=\"description\" content=\"Learn method overriding in Python OOP, how child classes modify parent methods, use super(), and implement runtime polymorphism.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/python\/lesson\/method-overriding\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Method Overriding - One Language. Endless Possibilities\" \/>\n<meta property=\"og:description\" content=\"Learn method overriding in Python OOP, how child classes modify parent methods, use super(), and implement runtime polymorphism.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/python\/lesson\/method-overriding\/\" \/>\n<meta property=\"og:site_name\" content=\"One Language. Endless Possibilities\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-16T04:25:09+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/method-overriding\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/method-overriding\\\/\",\"name\":\"Method Overriding - One Language. Endless Possibilities\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/#website\"},\"datePublished\":\"2026-03-02T03:42:37+00:00\",\"dateModified\":\"2026-03-16T04:25:09+00:00\",\"description\":\"Learn method overriding in Python OOP, how child classes modify parent methods, use super(), and implement runtime polymorphism.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/method-overriding\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/method-overriding\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/method-overriding\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"OBJECT ORIENTED PROGRAMMING IN PYTHON (OOP) > OOP Concepts > Method Overriding\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/python\\\/\",\"name\":\"One Language. Endless Possibilities\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/python\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Method Overriding - One Language. Endless Possibilities","description":"Learn method overriding in Python OOP, how child classes modify parent methods, use super(), and implement runtime polymorphism.","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:\/\/gigz.pk\/python\/lesson\/method-overriding\/","og_locale":"en_US","og_type":"article","og_title":"Method Overriding - One Language. Endless Possibilities","og_description":"Learn method overriding in Python OOP, how child classes modify parent methods, use super(), and implement runtime polymorphism.","og_url":"https:\/\/gigz.pk\/python\/lesson\/method-overriding\/","og_site_name":"One Language. Endless Possibilities","article_modified_time":"2026-03-16T04:25:09+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/python\/lesson\/method-overriding\/","url":"https:\/\/gigz.pk\/python\/lesson\/method-overriding\/","name":"Method Overriding - One Language. Endless Possibilities","isPartOf":{"@id":"https:\/\/gigz.pk\/python\/#website"},"datePublished":"2026-03-02T03:42:37+00:00","dateModified":"2026-03-16T04:25:09+00:00","description":"Learn method overriding in Python OOP, how child classes modify parent methods, use super(), and implement runtime polymorphism.","breadcrumb":{"@id":"https:\/\/gigz.pk\/python\/lesson\/method-overriding\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/python\/lesson\/method-overriding\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/python\/lesson\/method-overriding\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/python\/"},{"@type":"ListItem","position":2,"name":"OBJECT ORIENTED PROGRAMMING IN PYTHON (OOP) > OOP Concepts > Method Overriding"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/python\/#website","url":"https:\/\/gigz.pk\/python\/","name":"One Language. Endless Possibilities","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/python\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/lesson\/112","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/media?parent=112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}