{"id":21149,"date":"2017-04-25T20:15:11","date_gmt":"2017-04-25T20:15:11","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=21149"},"modified":"2017-04-25T20:15:11","modified_gmt":"2017-04-25T20:15:11","slug":"java-overriding-methods-what-it-means-and-rules-about-it","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/java-overriding-methods-what-it-means-and-rules-about-it\/","title":{"rendered":"Java:  overriding methods:  what it means, and rules about it"},"content":{"rendered":"<h1>Tutoring Java programming, you might be asked to clarify about overriding.  The tutor shares some thoughts.<\/h1>\n<p>In Java, when you override a method, you either<\/p>\n<ol>\n<li>define its performance (give it a &#8220;body&#8221;), or else<\/li>\n<li>redefine (change) its performance<\/li>\n<p>.\n<\/ol>\n<p>Case 1, above, refers to the situation of writing a subclass of an abstract class, or implementing an interface:  in either case, a method with undefined functionality must (typically) be defined, aka overridden.<\/p>\n<p>Case 2 often refers to the situation of writing a subclass that alters the performance of an inherited method. However, an instance of a class can have a method overridden as well.<\/p>\n<h6>Rules:<\/h6>\n<p>When overriding a method, its return type, name, and parameter list (including types) must be identical to its original ones [from the abstract class, interface, or base class].<\/p>\n<p><span style=\"font-family:monospace;font-size:120%\">@Override<\/span> can be used at the beginning of the line where the override is declared.  For example:<\/p>\n<p style=\"font-family:monospace;font-size:120%\">@Override public void method_x(String param0, int param1,&#8230;.){<\/p>\n<p> This may give the compiler extra opportunity to check the validity of the override, as well as improve the code&#8217;s human readability.<\/p>\n<p>Source:<\/p>\n<p><a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/java\/IandI\/override.html\">docs.oracle.com<\/a><\/p>\n<p>Jack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tutoring Java programming, you might be asked to clarify about overriding. The tutor shares some thoughts. In Java, when you override a method, you either define its performance (give it a &#8220;body&#8221;), or else redefine (change) its performance . Case &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/java-overriding-methods-what-it-means-and-rules-about-it\/\"> <span class=\"screen-reader-text\">Java:  overriding methods:  what it means, and rules about it<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105,1801],"tags":[2279,2280,2281,2282,2283],"class_list":["post-21149","post","type-post","status-publish","format-standard","hentry","category-computer-science","category-java","tag-override","tag-abstract-class-or-method","tag-interface","tag-rules-for-overriding-a-method-in-java","tag-what-does-overriding-mean-in-java"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/21149","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/comments?post=21149"}],"version-history":[{"count":34,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/21149\/revisions"}],"predecessor-version":[{"id":21183,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/21149\/revisions\/21183"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=21149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=21149"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=21149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}