Wednesday 18 July 2012

Polymorphism

class lcl_car DEFINITION.

PUBLIC SECTION.

METHODS: car, " method use for operation
         color.

ENDCLASS.

CLASS lcl_car IMPLEMENTATION.

METHOD: car.

  write :/ 'Plz select the new car'" Method implementation

  ENDMETHOD.

METHODcolor.

       write:/ 'The selecting car color is ' COLOR 4.

  ENDMETHOD.
  ENDCLASS.


class lci_car DEFINITION INHERITING FROM lcl_car.

PUBLIC SECTION.

  METHODs: car REDEFINITION"method  car is overriding
  ENDCLASS.

  CLASS lci_car IMPLEMENTATION.

  METHOD: car.
    CALL METHOD super->car.           " calling the base class using the super class.
    write: / 'The selected car is ford',
           / 'Do u like it'.

    ENDMETHOD.
    ENDCLASS.

load-OF-PROGRAM.
    data: lcl TYPE REF TO lci_car.
    create OBJECT: lcl.

    call METHOD: lcl->car,
                 lcl->color.

No comments:

Post a Comment