<br />
<b>Warning</b>:  Undefined array key "global_protection_id" in <b>/home/wikitechy/public_html/interview-questions/wp-content/plugins/content-protector/inc/class-ps-rest-handler.php</b> on line <b>51</b><br />
{"id":626,"date":"2021-07-13T23:07:03","date_gmt":"2021-07-13T23:07:03","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=626"},"modified":"2021-09-11T11:38:00","modified_gmt":"2021-09-11T11:38:00","slug":"what-is-the-purpose-of-method-overriding-in-java-where-we-are-completely-re-defining-a-inherited-method","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/java\/what-is-the-purpose-of-method-overriding-in-java-where-we-are-completely-re-defining-a-inherited-method\/","title":{"rendered":"What is the purpose of method overriding in java where we are completely re-defining a inherited method ?"},"content":{"rendered":"<div class=\"TextHeading\">\n<div class=\"hddn\">\n<h2 id=\"method-overriding-in-java\" class=\"color-purple\" style=\"text-align: justify;\">Method overriding in java<\/h2>\n<\/div>\n<\/div>\n<div class=\"Content\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<ul>\n<li>Declaring a method in sub class which is already present in parent class is known as method overriding.<\/li>\n<li>Overriding is done so that a child class can give its own implementation to a method which is already provided by the parent class.<\/li>\n<li>In this case the method in parent class is called overridden method and the method in child class is called overriding method.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<div class=\"TextHeading\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<h2 id=\"purpose-of-method-overriding\" class=\"color-purple\">Purpose of method overriding<\/h2>\n<\/div>\n<\/div>\n<div class=\"Content\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<ul>\n<li>The main purpose of method overriding is that the class can give its own specific implementation to a inherited method without even modifying the parent class code.<\/li>\n<li>This is helpful when a class has several child classes, so if a child class needs to use the parent class method, it can use it and the other classes that want to have different implementation can use overriding feature to make changes without touching the parent class code.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<div class=\"text-center row\" style=\"text-align: justify;\"><\/div>\n<div class=\"TextHeading\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<h2 id=\"difference-between-redefining-and-overriding\" class=\"color-blue\">Difference between Redefining and Overriding<\/h2>\n<\/div>\n<\/div>\n<div class=\"Content\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<ul>\n<li>The term &#8220;redefinition&#8221; isn&#8217;t usually used with regards to Java methods and inheritance. There are two terms that are commonly used: &#8220;override&#8221; and &#8220;overload.&#8221;<\/li>\n<li>Redefining and Overriding comes with in the same scenarios. Only difference is that if methods used are Static, its redefining.For Example,<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<div class=\"TextHeading\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<h2 id=\"overriding\" class=\"color-green\">Overriding<\/h2>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-java code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-java code-embed-code\">Class A<br\/>{<br\/>      public void show(){<br\/>             SOP(&quot;class a&quot;);<br\/>        }<br\/>   }<br\/><br\/>   Class B extends A<br\/>{<br\/>     public void show(){<br\/>         SOP(&quot;class B&quot;);<br\/>     }<br\/>   }<\/code><\/pre> <\/div>\n<\/div>\n<\/div>\n<div class=\"TextHeading\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<h2 id=\"redefining\" class=\"color-green\">Redefining<\/h2>\n<\/div>\n<\/div>\n<div class=\"CodeContent\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<figure class=\"highlight\"><div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-java code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-java code-embed-code\">Class A<br\/>{<br\/>      public static void show(){<br\/>             SOP(&quot;class a&quot;);<br\/>        }<br\/>   }<br\/><br\/>   Class B extends A<br\/>{<br\/>     public static void show(){<br\/>         SOP(&quot;class B&quot;);<br\/>     }<br\/>   }<\/code><\/pre> <\/div><\/figure>\n<\/div>\n<\/div>\n<p class=\"note\" style=\"text-align: justify;\">Note: Static methods looks as if they are over-rided but they are actually redefined.<\/p>\n<div class=\"Content\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<ul>\n<li>Redefining is with Static Methods.<\/li>\n<li>Static methods are associated with Class and not with Object, so we do not override as per instance for run-time.<\/li>\n<li>In case of static we are just redefining the method.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<div class=\"TextHeading\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<h2 id=\"re-defining-a-inherited-method\" class=\"color-purple\">Re-defining a Inherited Method<\/h2>\n<ul>\n<li>Re-defining involves a inherited method like Replacement and Refinement<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<div class=\"TextHeading\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<h2 id=\"replacement\" class=\"color-blue\">Replacement<\/h2>\n<\/div>\n<\/div>\n<div class=\"CodeContent\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<figure class=\"highlight\">\n<pre><code id=\"code3\" class=\"hljs bash\" data-lang=\"\"><span class=\"nt\">**Replacement** is the <span class=\"hljs-keyword\">case<\/span> <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-built_in\">which<\/span> child class is overriding<\/span><\/code><\/pre>\n<\/figure>\n<\/div>\n<\/div>\n<div class=\"Content\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<ul>\n<li>The inherited method of parent class with a behavior(functionality) which is completely different from corresponding parent method and a sign for this process is not calling super.method() in the body of child method.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<div class=\"TextHeading\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<h2 id=\"refinement\" class=\"color-blue\">Refinement<\/h2>\n<\/div>\n<\/div>\n<div class=\"Output\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<figure class=\"highlight\">\n<pre><code class=\"hljs bash\" data-lang=\"\"><span class=\"nt\">Refinement is the <span class=\"hljs-keyword\">case<\/span> <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-built_in\">which<\/span> child is overriding inherited  <\/span><\/code><\/pre>\n<\/figure>\n<\/div>\n<\/div>\n<div class=\"Content\">\n<div class=\"hddn\">\n<ul>\n<li style=\"text-align: justify;\">The method from parent with a functionality related to parent method functionality, sign of this process is calling generally super.method() in the body of child method.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Answer : Exception in Java represents that problem arises during the execution of the program&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"passster_activate_protection":false,"passster_protect_child_pages":"","passster_protection_type":"password","passster_password":"","passster_activate_overwrite_defaults":"","passster_headline":"","passster_instruction":"","passster_placeholder":"","passster_button":"","passster_id":"","passster_activate_misc_settings":"","passster_redirect_url":"","passster_hide":"no","passster_area_shortcode":"","gtb_hide_title":false,"gtb_wrap_title":false,"gtb_class_title":"","gtb_remove_headerfooter":false,"footnotes":""},"categories":[4004],"tags":[195,491,360,203,199,214,198,363,209,205,16512,2936,222,196,212,213,15931,286,16509,16511,16516,16515,16513,207,366,204,16510,16514,217,282,4023,483,206,200,197,280,364,16517,968],"class_list":["post-626","post","type-post","status-publish","format-standard","hentry","category-java","tag-accenture-interview-questions-and-answers","tag-applied-materials-interview-questions-and-answers","tag-atos-interview-questions-and-answers","tag-capgemini-interview-questions-and-answers","tag-casting-networks-india-pvt-limited-interview-questions-and-answers","tag-cgi-group-inc-interview-questions-and-answers","tag-chetu-interview-questions-and-answers","tag-ciena-corporation-interview-questions-and-answers","tag-collabera-technologies-interview-questions-and-answers","tag-dell-international-services-india-pvt-ltd-interview-questions-and-answers","tag-difference-between-overloading-and-overriding-in-java","tag-fis-global-business-solutions-india-pvt-ltd-interview-questions-and-answers","tag-flipkart-interview-questions-and-answers","tag-ibm-interview-questions-and-answers","tag-indecomm-global-services-interview-questions-and-answers","tag-infosys-technologies-interview-questions-and-answers","tag-kumaran-systems-interview-questions-and-answers","tag-lt-infotech-interview-questions-and-answers","tag-method-overloading-and-method-overriding-in-java-with-realtime-examples","tag-method-overloading-and-overriding-in-c","tag-method-overriding-in-c-tutorialspoint","tag-method-overriding-in-c-with-real-time-example","tag-method-overriding-java","tag-mphasis-interview-questions-and-answers","tag-netapp-interview-questions-and-answers","tag-oracle-corporation-interview-questions-and-answers","tag-overloading-and-overriding-in-oops","tag-overriding-java","tag-peoplestrong-interview-questions-and-answers","tag-persistent-systems-interview-questions-and-answers","tag-rbs-india-de-interview-questions-and-answers","tag-reliance-industries-ltd-interview-questions-and-answers","tag-sap-labs-india-pvt-ltd-interview-questions-and-answers","tag-tech-mahindra-interview-questions-and-answers","tag-unitedhealth-group-interview-questions-and-answers","tag-virtusa-consulting-services-pvt-ltd-interview-questions-and-answers","tag-wells-fargo-interview-questions-and-answers","tag-why-we-use-method-overriding-in-java","tag-wipro-infotech-interview-questions-and-answers"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What is the purpose of method overriding in java - Wikitechy<\/title>\n<meta name=\"description\" content=\"What is the purpose of method overriding in java where we are completely re-defining a inherited method ? - We can change default behavior of super class method\" \/>\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.wikitechy.com\/interview-questions\/java\/what-is-the-purpose-of-method-overriding-in-java-where-we-are-completely-re-defining-a-inherited-method\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is the purpose of method overriding in java - Wikitechy\" \/>\n<meta property=\"og:description\" content=\"What is the purpose of method overriding in java where we are completely re-defining a inherited method ? - We can change default behavior of super class method\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/java\/what-is-the-purpose-of-method-overriding-in-java-where-we-are-completely-re-defining-a-inherited-method\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-13T23:07:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-09-11T11:38:00+00:00\" \/>\n<meta name=\"author\" content=\"Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Editor\" \/>\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\":\"WebPage\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/java\/what-is-the-purpose-of-method-overriding-in-java-where-we-are-completely-re-defining-a-inherited-method\/\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/java\/what-is-the-purpose-of-method-overriding-in-java-where-we-are-completely-re-defining-a-inherited-method\/\",\"name\":\"What is the purpose of method overriding in java - Wikitechy\",\"isPartOf\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\"},\"datePublished\":\"2021-07-13T23:07:03+00:00\",\"dateModified\":\"2021-09-11T11:38:00+00:00\",\"author\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757\"},\"description\":\"What is the purpose of method overriding in java where we are completely re-defining a inherited method ? - We can change default behavior of super class method\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wikitechy.com\/interview-questions\/java\/what-is-the-purpose-of-method-overriding-in-java-where-we-are-completely-re-defining-a-inherited-method\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/\",\"name\":\"Wikitechy\",\"description\":\"Interview Questions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757\",\"name\":\"Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g\",\"caption\":\"Editor\"},\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/author\/editor\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is the purpose of method overriding in java - Wikitechy","description":"What is the purpose of method overriding in java where we are completely re-defining a inherited method ? - We can change default behavior of super class method","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.wikitechy.com\/interview-questions\/java\/what-is-the-purpose-of-method-overriding-in-java-where-we-are-completely-re-defining-a-inherited-method\/","og_locale":"en_US","og_type":"article","og_title":"What is the purpose of method overriding in java - Wikitechy","og_description":"What is the purpose of method overriding in java where we are completely re-defining a inherited method ? - We can change default behavior of super class method","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/java\/what-is-the-purpose-of-method-overriding-in-java-where-we-are-completely-re-defining-a-inherited-method\/","og_site_name":"Wikitechy","article_published_time":"2021-07-13T23:07:03+00:00","article_modified_time":"2021-09-11T11:38:00+00:00","author":"Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Editor","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/java\/what-is-the-purpose-of-method-overriding-in-java-where-we-are-completely-re-defining-a-inherited-method\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/java\/what-is-the-purpose-of-method-overriding-in-java-where-we-are-completely-re-defining-a-inherited-method\/","name":"What is the purpose of method overriding in java - Wikitechy","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"datePublished":"2021-07-13T23:07:03+00:00","dateModified":"2021-09-11T11:38:00+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757"},"description":"What is the purpose of method overriding in java where we are completely re-defining a inherited method ? - We can change default behavior of super class method","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/java\/what-is-the-purpose-of-method-overriding-in-java-where-we-are-completely-re-defining-a-inherited-method\/"]}]},{"@type":"WebSite","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website","url":"https:\/\/www.wikitechy.com\/interview-questions\/","name":"Wikitechy","description":"Interview Questions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757","name":"Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g","caption":"Editor"},"url":"https:\/\/www.wikitechy.com\/interview-questions\/author\/editor\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/626","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/comments?post=626"}],"version-history":[{"count":3,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/626\/revisions"}],"predecessor-version":[{"id":3423,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/626\/revisions\/3423"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=626"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=626"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=626"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}