Final Classes and Methods in Object Oriented Programming

...Previous

Go to Methods tab,  

Enter Method name, Level, Visibility and Description as shown in the below screen shot

 

Double click on the Method name "VOLUM"; it goes to method Implementation screen. As shown below

 

To define method "VOLUM" as a Final method,  

Go to Menu path, then Goto -> Method definition

 

Pop-up window is displayed  

Go to "Attributes" tab, check the check box "Final" and then press "Change" button.  

 

A successful message is displayed like "Method changed successfully"

 

Write the below code in Method volum  

METHOD volum.
* Local Data Declarations
  DATA: lv_vol TYPE i.

  lv_vol = length * width * height.
  WRITE'Volume of a Rectangle:', lv_vol.
* Clear variable
  CLEAR: lv_vol.
ENDMETHOD.

Then save and activate the class and method.

b) Creating Sub Class:

TCode: SE24  

Enter the name of class as 'Z_DEMO_SUB_CLASS' and press Create Button to create sub class 

 

A pop-up window is displayed, then select "Class" radio button and

Press enter

 

Enter the Description of the class and then select the inheritance button   , to inherit the super class.

 

Enter the Super class name as "Z_DEMO_SUP_CLASS", which is being created earlier and press "Save" button.  

 

The Attributes and methods defined in the super class will automatically come into the sub class.  

If you try to redefine or modify the super class method "VOLUM", go to the Methods tab, select the "VOLUM" method and click on

"Redefine" button  ,

 

It gives a message like below and not allowed to redefine or modify the method in sub class.

 

The method implementation "VOLUM" can be used in both super class "Z_DEMO_SUP_CLASS" and sub class "Z_DEMO_SUB_CLASS".

Execute the sub class "Z_DEMO_SUB_CLASS" by pressing  (F8) button  

It goes to below screen, then enter values under "LENGTH, HEIGHT and WIDTH" as "2, 3 and 4" and Press execute button .

 

The output will be displayed like below.

 

Same as sub class, you can also execute the super class "Z_DEMO_SUP_CLASS", the same output will be displayed.

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image