{"id":7647,"date":"2025-08-27T13:21:16","date_gmt":"2025-08-27T07:51:16","guid":{"rendered":"https:\/\/www.sapewmhelp.com\/?question=how-to-achieve-multiple-inheritance-using-interface-in-sap"},"modified":"2025-08-27T13:21:16","modified_gmt":"2025-08-27T07:51:16","slug":"how-to-achieve-multiple-inheritance-using-interface-in-sap","status":"publish","type":"question","link":"https:\/\/www.sapewmhelp.com\/?question=how-to-achieve-multiple-inheritance-using-interface-in-sap","title":{"rendered":"How to achieve multiple inheritance using interface in SAP ?"},"content":{"rendered":"<p>A class can implement <strong>multiple interfaces<\/strong> at once, which allows you to combine functionality from many sources.<\/p>\n<p><strong>Example:\u00a0<\/strong><\/p>\n<p>&#8221; First interface<br \/>\nINTERFACE if_flyable.<br \/>\nMETHODS: fly.<br \/>\nENDINTERFACE.<\/p>\n<p>&#8221; Second interface<br \/>\nINTERFACE if_swimmable.<br \/>\nMETHODS: swim.<br \/>\nENDINTERFACE.<\/p>\n<p>&#8221; A class implementing multiple interfaces<br \/>\nCLASS cl_duck DEFINITION.<br \/>\nPUBLIC SECTION.<br \/>\nINTERFACES: if_flyable,<br \/>\nif_swimmable.<br \/>\nMETHODS: display.<br \/>\nENDCLASS.<\/p>\n<p>CLASS cl_duck IMPLEMENTATION.<br \/>\nMETHOD if_flyable~fly.<br \/>\nWRITE: \/ &#8216;The duck is flying.&#8217;.<br \/>\nENDMETHOD.<\/p>\n<p>METHOD if_swimmable~swim.<br \/>\nWRITE: \/ &#8216;The duck is swimming.&#8217;.<br \/>\nENDMETHOD.<\/p>\n<p>METHOD display.<br \/>\nWRITE: \/ &#8216;I am a duck with multiple abilities!&#8217;.<br \/>\nENDMETHOD.<br \/>\nENDCLASS.<\/p>\n<p>START-OF-SELECTION.<br \/>\nDATA(duck) = NEW cl_duck( ).<\/p>\n<p>duck-&gt;display( ).<br \/>\nduck-&gt;if_flyable~fly( ).<br \/>\nduck-&gt;if_swimmable~swim( ).<\/p>\n<p>Output:<\/p>\n<p>I am a duck with multiple abilities!<br \/>\nThe duck is flying.<br \/>\nThe duck is swimming.<\/p>\n<h5>Key Points:<\/h5>\n<ul>\n<li>\n<p><code>CLASS \u2026 DEFINITION<\/code> uses <code>INTERFACES:<\/code> to include multiple interfaces.<\/p>\n<\/li>\n<li>\n<p>Methods from interfaces must be implemented in the class.<\/p>\n<\/li>\n<li>\n<p>When calling interface methods, you can:<\/p>\n<ul>\n<li>\n<p>Use <strong>fully qualified names<\/strong>: <code>object-&gt;if_interface~method( )<\/code><\/p>\n<\/li>\n<li>\n<p>Or, if redefined explicitly as public methods, call them directly.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>This is the standard way to achieve &#8220;multiple inheritance&#8221; in ABAP.<\/p>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","question-category":[158],"question_tags":[178,263,378,377,177],"class_list":["post-7647","question","type-question","status-publish","hentry","question-category-abap","question_tags-abap","question_tags-interface","question_tags-multiple-inheritance","question_tags-oop","question_tags-sap"],"_links":{"self":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question\/7647","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=7647"}],"wp:attachment":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7647"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion-category&post=7647"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion_tags&post=7647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}