Saturday, 4 March 2017

Final Class & Method in OOP ABAP


Need to check and  comment some lines of code in the program, because for understanding I have written all the possibilities………


REPORT  
zcl_oops_test.

CLASS cl_final DEFINITION FINAL.    "Can not be inherited....
**** methods can not be inherited of final class - while defining inside final class it becomes final method automatically.....
  
PUBLIC SECTION

  
METHODSname.

  
ENDCLASS.

class cl_final definition.

  
PUBLIC SECTION.
  
methodsname FINAL.         "Can not be inherited...
 
  
methodsdetails.            "Can be inherited.....

  
ENDCLASS.

  
CLASS cl_final IMPLEMENTATION.

    
method name.
      
write:'Final Method'.

      
ENDMETHOD.
      
method details.
      
write:'Another Method of Super Class'.

      
ENDMETHOD.

      
ENDCLASS.
*
      
CLASS cl_inherit DEFINITION INHERITING FROM cl_final.

        
PUBLIC SECTION.
        
methodsname REDEFINITION.           ""Can not be redefined...


        
METHODsdetails REDEFINITION.        ""Can be redefined...



      
ENDCLASS.

      
class cl_inherit IMPLEMENTATION.

        
method name.
          
write:'Inherited Class'.
          
ENDMETHOD.

    
method details.
    
write:'Another Method of Sub Class'.
    
ENDMETHOD.
          
ENDCLASS.


      
START-OF-SELECTION.

      
dataobj1 type REF TO cl_final,
            obj2 
type REF TO cl_inherit.


      
create OBJECTobj1,
                    obj2
.
     
      
call method obj1->name.
      
call method obj2->name.
      
call method obj1->details.
      
call method obj2->details.

No comments:

Post a Comment