An interface can only be declared in the public section of any class. Any other section will cause a syntax error in the system.
Here is a program where we have declared an Interface it. We have defined attribute and method in this interface. Next, we have defined a class where we have declared the interface in the protected section. After implementing the method we compile the program and a syntax error has come as follows.
Now Comment the protected section and execute the program
REPORT zinterface_public.
*----------------------------------------------------------------------*
* INTERFACE it
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
INTERFACE it.
DATA v_txt TYPE char50.
METHODS meth.
ENDINTERFACE. "it
*----------------------------------------------------------------------*
* CLASS cls DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls DEFINITION.
PUBLIC SECTION.
DATA date TYPE sy-datum.
* PROTECTED SECTION.
INTERFACES it.
ENDCLASS. "cls DEFINITION
*----------------------------------------------------------------------*
* CLASS cls IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls IMPLEMENTATION.
METHOD it~meth.
date = sy-datum.
WRITE: / it~v_txt,
/ 'Today''s Date is', date DD/MM/YYYY.
ENDMETHOD. "it~meth
ENDCLASS. "cls IMPLEMENTATION
START-OF-SELECTION.
DATA obj TYPE REF TO cls.
CREATE OBJECT obj.
obj->it~v_txt = 'SAP ABAP Object Oriented'.
CALL METHOD obj->it~meth.
Output