You are on page 1of 2

interface ZIF_PLANE

public .
methods fly.
methods loading.
endinterface.

class ZCL_PASSENGER_PLANE definition


public
inheriting from ZCL_AC_PLANE
final
create public .

public section.

methods ZIF_PLANE~LOADING
redefinition .
protected section.
private section.
ENDCLASS.

CLASS ZCL_PASSENGER_PLANE IMPLEMENTATION.

method ZIF_PLANE~LOADING.
WRITE : 'Passngers are boarding'.
endmethod.
ENDCLASS.

CLASS ZCL_AC_PLANE IMPLEMENTATION.

method ZIF_PLANE~FLY.
WRITE : / 'Engines are bootup, We are running on runway...'.
WRITE : / 'Roger! we are in sky, thanks for successful take-off'.
WRITE : / 'Auto pilot mode ON'.
endmethod.
ENDCLASS.

class ZCL_AC_PLANE definition


public
abstract
create public .

public section.

interfaces ZIF_PLANE
abstract methods LOADING .
protected section.
private section.
ENDCLASS.

class ZCL_CARGO_PLANE definition


public
inheriting from ZCL_AC_PLANE
final
create public .

public section.

methods ZIF_PLANE~LOADING
redefinition .
protected section.
private section.
ENDCLASS.

CLASS ZCL_CARGO_PLANE IMPLEMENTATION.

method ZIF_PLANE~LOADING.
WRITE : 'Freight is getting loaded via conveyer'.
endmethod.
ENDCLASS.

*&---------------------------------------------------------------------*
*& Report zabap_basic_report
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zabap_basic_report.

parameters : p_type type c.

data: lo_pass type ref to zcl_passenger_plane,


lo_cargo type ref to zcl_cargo_plane,
lo_plane type ref to zif_plane.

if p_type = 'P'.
create object lo_pass.
lo_plane = lo_pass.
else.
create object lo_cargo.
lo_plane = lo_cargo.
endif.

lo_plane->loading( ). ""a method with same name behaving differently Polymorphism -


Poly ( Many ) + Morphism ( Forms ) - Runtime

lo_plane->fly( ).

You might also like