Instance Operator- NEW(Part 2)


Instance Operator NEW can be used to create Instance/object of any Class.

CLASS lcl_demo DEFINITION.
  PUBLIC SECTION.
    METHODS disp.
ENDCLASS.

CLASS lcl_demo IMPLEMENTATION.
  METHOD disp.
    WRITE :‘Hello’.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
* Old way to create an Object and calling the method
  DATA obj1 TYPE REF TO lcl_demo.
  CREATE OBJECT obj1.
  CALL METHOD obj1->disp.

* New way(1) to create an Object
  DATA obj2 TYPE REF TO lcl_demo.
  obj2 NEW #).
  CALL METHOD obj2->disp.

* New way(2) to create an Object
  DATA obj3 TYPE REF TO lcl_demo.
  obj3 =  NEW lcl_demo).
  CALL METHOD obj3->disp.

* New way(3) to create an Object
  NEW lcl_demo)->disp).


56


 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s