{"id":3644,"date":"2018-07-20T16:00:49","date_gmt":"2018-07-20T16:00:49","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=3644"},"modified":"2024-08-09T08:45:33","modified_gmt":"2024-08-09T08:45:33","slug":"method-overriding-in-java-example","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/method-overriding-in-java-example\/","title":{"rendered":"Method Overriding in Java Example"},"content":{"rendered":"<h2>Method Overriding in Java Example<\/h2>\n<p>An instance method in a child class that has the same method signature of the parent class is sail to be overriding the parent&#8217;s class method. Using this feature we can provide a child-specific implementation for the method. We can use the @Ovevrride annotation when we are overriding the method.<\/p>\n<p><b>Method signature\u00a0 =\u00a0 access specifier\u00a0&lt;method return type&gt; name of the method( method parameters)<\/b><\/p>\n<p>&nbsp;<\/p>\n<h3><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3740\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Overloading-and-Overriding-in-Java.png\" alt=\"Overloading and Overriding in Java\" width=\"1734\" height=\"890\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Overloading-and-Overriding-in-Java.png 1734w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Overloading-and-Overriding-in-Java-300x154.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Overloading-and-Overriding-in-Java-1024x526.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Overloading-and-Overriding-in-Java-768x394.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Overloading-and-Overriding-in-Java-1536x788.png 1536w\" sizes=\"auto, (max-width: 1734px) 100vw, 1734px\" \/><\/h3>\n<h3>Coding Listing<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\/**\r\n * \r\n *\/\r\npackage com.testingdocs.tutorial;\r\n\r\n\/**\r\n * @author TestingDocs\r\n *\r\n *\/\r\npublic class Document {\r\n  public void printDoc() {\r\n    System.out.println(\"Print Parent Document...\");\r\n  }\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h3>Child class<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.testingdocs.tutorial;\r\n\r\npublic class TestPlan extends Document {\r\n\r\n  @Override\r\n  public void printDoc() {\r\n    \/\/Overridden method \r\n    System.out.println(\"Print Child TestPlan...\");\r\n  }\r\n\r\n  public static void main(String[] args) {\r\n       TestPlan tp=new TestPlan();\r\n       tp.printDoc();\r\n  }\r\n\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h3>Screenshot<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3686\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Method-Overridding-in-Java.png\" alt=\"Method Overridding in Java\" width=\"1728\" height=\"1023\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Method-Overridding-in-Java.png 1728w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Method-Overridding-in-Java-300x178.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Method-Overridding-in-Java-1024x606.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Method-Overridding-in-Java-768x455.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Method-Overridding-in-Java-1536x909.png 1536w\" sizes=\"auto, (max-width: 1728px) 100vw, 1728px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&#8212;<\/p>\n<p>Java Tutorial on this website:<\/p>\n<p><a href=\"https:\/\/www.testingdocs.com\/java-tutorial\/\">https:\/\/www.testingdocs.com\/java-tutorial\/<\/a><\/p>\n<p>For more information on Java, visit the official website :<\/p>\n<p><a href=\"https:\/\/www.oracle.com\/in\/java\/\" rel=\"noopener\">https:\/\/www.oracle.com\/in\/java\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Method Overriding in Java Example An instance method in a child class that has the same method signature of the parent class is sail to be overriding the parent&#8217;s class method. Using this feature we can provide a child-specific implementation for the method. We can use the @Ovevrride annotation when we are overriding the method. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[40],"tags":[],"class_list":["post-3644","post","type-post","status-publish","format-standard","hentry","category-java","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"_links":{"self":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/3644","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/comments?post=3644"}],"version-history":[{"count":11,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/3644\/revisions"}],"predecessor-version":[{"id":23799,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/3644\/revisions\/23799"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=3644"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=3644"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=3644"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}