{"id":57,"date":"2026-05-20T19:03:54","date_gmt":"2026-05-20T19:03:54","guid":{"rendered":"https:\/\/gigz.pk\/csharp\/?post_type=lesson&#038;p=57"},"modified":"2026-05-20T19:04:16","modified_gmt":"2026-05-20T19:04:16","slug":"method-overriding","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/csharp\/?lesson=method-overriding","title":{"rendered":"Method Overriding"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Method overriding is an important concept in C# Object-Oriented Programming that allows a derived class to provide a specific implementation of a method that is already defined in its base class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is Method Overriding<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Method overriding occurs when a child class (derived class) changes the behavior of a method that is inherited from the parent class (base class). It is used to achieve runtime polymorphism.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How Method Overriding Works<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The base class defines a method using the virtual keyword, and the derived class overrides it using the override keyword. When the method is called, the version that executes depends on the object type at runtime.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Virtual Keyword<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The virtual keyword is used in the base class to allow a method to be overridden in a derived class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Override Keyword<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The override keyword is used in the derived class to provide a new implementation of the base class method.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Importance of Method Overriding<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Method overriding allows flexibility in programming by enabling different behaviors for the same method depending on the object.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Real World Usage<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">It is used in systems like payment processing, game development, and user role management where different classes require different implementations of the same action.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Method Overriding vs Method Overloading<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Method overriding works between base and derived classes and changes method behavior, while method overloading involves multiple methods with the same name but different parameters in the same class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Advantages<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Supports runtime polymorphism<br>Improves code flexibility<br>Enhances reusability<br>Allows customized behavior<br>Makes applications scalable<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Common Mistakes<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Forgetting to use virtual keyword in base class<br>Not using override keyword correctly<br>Incorrect method signatures<br>Confusing overriding with overloading<br>Poor class design<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Best Practices<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use method overriding for behavior customization<br>Keep method signatures consistent<br>Use clear class hierarchy<br>Avoid unnecessary overriding<br>Follow OOP principles<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Lesson Summary<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Method overriding in C# allows a derived class to change the behavior of a base class method. It is a key feature of polymorphism and helps build flexible and reusable applications.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/csharp\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">Intermediate C# > Inheritance and Polymorphism > 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-1779303813847\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n","protected":false},"menu_order":35,"template":"","class_list":["post-57","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Method Overriding - Learn C# Language with GiGz.PK<\/title>\n<meta name=\"description\" content=\"Learn C# method overriding. Understand runtime polymorphism using virtual and override keywords with simple examples.\" \/>\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\/csharp\/?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 - Learn C# Language with GiGz.PK\" \/>\n<meta property=\"og:description\" content=\"Learn C# method overriding. Understand runtime polymorphism using virtual and override keywords with simple examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/csharp\/?lesson=method-overriding\" \/>\n<meta property=\"og:site_name\" content=\"Learn C# Language with GiGz.PK\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-20T19:04:16+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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/csharp\\\/?lesson=method-overriding\",\"url\":\"https:\\\/\\\/gigz.pk\\\/csharp\\\/?lesson=method-overriding\",\"name\":\"Method Overriding - Learn C# Language with GiGz.PK\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/csharp\\\/#website\"},\"datePublished\":\"2026-05-20T19:03:54+00:00\",\"dateModified\":\"2026-05-20T19:04:16+00:00\",\"description\":\"Learn C# method overriding. Understand runtime polymorphism using virtual and override keywords with simple examples.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/csharp\\\/?lesson=method-overriding#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/csharp\\\/?lesson=method-overriding\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/csharp\\\/?lesson=method-overriding#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/csharp\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Intermediate C# > Inheritance and Polymorphism > Method Overriding\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/csharp\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/csharp\\\/\",\"name\":\"Learn C# Language with GiGz.PK\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/csharp\\\/?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 - Learn C# Language with GiGz.PK","description":"Learn C# method overriding. Understand runtime polymorphism using virtual and override keywords with simple examples.","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\/csharp\/?lesson=method-overriding","og_locale":"en_US","og_type":"article","og_title":"Method Overriding - Learn C# Language with GiGz.PK","og_description":"Learn C# method overriding. Understand runtime polymorphism using virtual and override keywords with simple examples.","og_url":"https:\/\/gigz.pk\/csharp\/?lesson=method-overriding","og_site_name":"Learn C# Language with GiGz.PK","article_modified_time":"2026-05-20T19:04:16+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/csharp\/?lesson=method-overriding","url":"https:\/\/gigz.pk\/csharp\/?lesson=method-overriding","name":"Method Overriding - Learn C# Language with GiGz.PK","isPartOf":{"@id":"https:\/\/gigz.pk\/csharp\/#website"},"datePublished":"2026-05-20T19:03:54+00:00","dateModified":"2026-05-20T19:04:16+00:00","description":"Learn C# method overriding. Understand runtime polymorphism using virtual and override keywords with simple examples.","breadcrumb":{"@id":"https:\/\/gigz.pk\/csharp\/?lesson=method-overriding#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/csharp\/?lesson=method-overriding"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/csharp\/?lesson=method-overriding#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/csharp"},{"@type":"ListItem","position":2,"name":"Intermediate C# > Inheritance and Polymorphism > Method Overriding"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/csharp\/#website","url":"https:\/\/gigz.pk\/csharp\/","name":"Learn C# Language with GiGz.PK","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/csharp\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/csharp\/index.php?rest_route=\/wp\/v2\/lesson\/57","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/csharp\/index.php?rest_route=\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/csharp\/index.php?rest_route=\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/csharp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=57"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}