Short Break (ABAP Objects)

1. Is it possible to create a class with definition part but not implementation part?

Yes. We can create class without the implementation part
 whenever the class does not have any methods but only attributes.


Eg.
REPORT  ZSAMPLE.
class lcl_sample definition.
  public section.
  data name(30) value 'LINO MATHEW'.
  endclass.

data lo_sample type ref to lcl_sample.
create object lo_sample.
write lo_sample->name.

Output:




2. Which is the default visibility section for a class?

There is no default visibility section. It is necessary to provide one of
the following visibility sections.
* Public Section
* Private Section
* Protected Section


Eg.
REPORT  ZSAMPLE.
class lcl_sample definition.
  data num type i.
  endclass.

The above program will throw the compilation error as
There is no "PUBLIC ...", "PROTECTED..." or "PRIVATE SECTION" statement.

No comments:

Post a Comment