{"id":7163,"date":"2025-07-30T22:57:32","date_gmt":"2025-07-30T17:27:32","guid":{"rendered":"https:\/\/www.sapewmhelp.com\/?question=method-overriding"},"modified":"2025-07-31T10:36:28","modified_gmt":"2025-07-31T05:06:28","slug":"method-overriding","status":"publish","type":"question","link":"https:\/\/www.sapewmhelp.com\/?question=method-overriding","title":{"rendered":"Method Overriding in SAP ABAP with Example"},"content":{"rendered":"<p>Method overriding allows a subclass to provide a new implementation of a method that is already defined in the superclass. The method in the subclass must use the REDEFINITION keyword.<\/p>\n<h3 data-start=\"387\" data-end=\"413\"><strong>When to use it:<\/strong><\/h3>\n<ul>\n<li>\n<p>When a general method in a parent class needs to be customized for specific child behavior.<\/p>\n<\/li>\n<li>\n<p>To implement polymorphism (different behavior for the same method call).<\/p>\n<\/li>\n<\/ul>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code><!--StartFragment --><span><span>CLASS\u00a0<\/span>cl_parent\u00a0<span>DEFINITION<\/span><span>.<\/span>\r\n\u00a0\u00a0<span>PUBLIC\u00a0<\/span><span>SECTION<\/span><span>.<\/span>\r\n\u00a0\u00a0\u00a0\u00a0<span>METHODS<\/span><span>:\u00a0<\/span>display<span>.<\/span>\r\n<span>ENDCLASS<\/span><span>.<\/span>\r\n\r\n<span>CLASS\u00a0<\/span>cl_parent\u00a0<span>IMPLEMENTATION<\/span><span>.<\/span>\r\n\u00a0\u00a0<span>METHOD\u00a0<\/span>display<span>.<\/span>\r\n\u00a0\u00a0\u00a0\u00a0<span>WRITE<\/span><span>:\u00a0<\/span>'Parent\u00a0<span>class\u00a0<\/span>method'<span>.<\/span>\r\n\u00a0\u00a0<span>ENDMETHOD<\/span><span>.<\/span>\r\n<span>ENDCLASS<\/span><span>.<\/span>\r\n\r\n<span>CLASS\u00a0<\/span>cl_child\u00a0<span>DEFINITION\u00a0<\/span><span>INHERITING\u00a0<\/span><span>FROM\u00a0<\/span>cl_parent<span>.<\/span>\r\n\u00a0\u00a0<span>PUBLIC\u00a0<\/span><span>SECTION<\/span><span>.<\/span>\r\n\u00a0\u00a0\u00a0\u00a0<span>METHODS<\/span><span>:\u00a0<\/span>display\u00a0<span>REDEFINITION<\/span><span>.<\/span>\r\n<span>ENDCLASS<\/span><span>.<\/span>\r\n\r\n<span>CLASS\u00a0<\/span>cl_child\u00a0<span>IMPLEMENTATION<\/span><span>.<\/span>\r\n\u00a0\u00a0<span>METHOD\u00a0<\/span>display<span>.<\/span>\r\n\u00a0\u00a0\u00a0\u00a0<span>WRITE<\/span><span>:\u00a0<\/span>'Child\u00a0<span>class\u00a0<\/span><span>method\u00a0<\/span><span>-\u00a0<\/span>overridden'<span>.<\/span>\r\n\u00a0\u00a0<span>ENDMETHOD<\/span><span>.<\/span>\r\n<span>ENDCLASS<\/span><span>.<\/span>\r\n\r\n<span>START-OF-SELECTION<\/span><span>.<\/span>\r\n\u00a0\u00a0<span>DATA<\/span><span>(<\/span>lo_obj<span>)\u00a0<\/span><span>=\u00a0<\/span><span>NEW\u00a0<\/span>cl_child<span>(\u00a0<\/span><span>)<\/span><span>.<\/span>\r\n\u00a0\u00a0lo_obj<span>-&gt;<\/span>display<span>(\u00a0<\/span><span>)<\/span><span>.<\/span><\/span> <\/code><\/pre>\n<\/div>\n<p>OutPut:<br \/>\n<img decoding=\"async\" class=\"content-img\" src=\"https:\/\/www.sapewmhelp.com\/wp-content\/uploads\/2025\/07\/overriding.png\" \/><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","question-category":[174],"question_tags":[171,196,191,195,168,177],"class_list":["post-7163","question","type-question","status-publish","hentry","question-category-ooabap","question_tags-class","question_tags-method","question_tags-method-overriding","question_tags-object","question_tags-ooabap","question_tags-sap"],"_links":{"self":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question\/7163","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question"}],"about":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7163"}],"wp:attachment":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7163"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion-category&post=7163"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion_tags&post=7163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}