An object has the following three main characteristics −
The state of an object can be described as a set of attributes and their values. For example, a bank account has a set of attributes such as Account Number, Name, Account Type, Balance, and values of all these attributes. The behavior of an object refers to the changes that occur in its attributes over a period of time.
Each object has a unique identity that can be used to distinguish it from other objects. Two objects may exhibit the same behavior and they may or may not have the same state, but they never have the same identity. Two persons may have the same name, age, and gender but they are not identical. Similarly, the identity of an object will never change throughout its lifetime.
Objects can interact with one another by sending messages. Objects contain data and code to manipulate the data. An object can also be used as a user-defined data type with the help of a class. Objects are also called variables of the type class. After defining a class, you can create any number of objects belonging to that class. Each object is associated with the data of the type class with which it has been created.
The object creation usually includes the following steps −
DATA: <object_name> TYPE REF TO <class_name>.
CREATE Object: <object_name>.
REPORT ZDEMO_OBJECT.
CLASS Class1 Definition.
Public Section.
DATA: text1(45) VALUE 'ABAP Objects.'.
METHODS: Display1.
ENDCLASS.
CLASS Class1 Implementation.
METHOD Display1.
Write:/ 'This is the Display method.'.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA: Class1 TYPE REF TO Class1.
CREATE Object: Class1.
Write:/ Class1->text1.
CALL METHOD: Class1->Display1.
The above code produces the following output −
ABAP Objects.
This is the Display method.
73 videos|68 docs
|
1. What is Object-Oriented Programming in SAP ABAP? |
2. How do you create an object in SAP ABAP? |
3. What are the benefits of using Objects in SAP ABAP? |
4. How can you implement inheritance in SAP ABAP Objects? |
5. Can you explain the concept of polymorphism in SAP ABAP Objects? |
|
Explore Courses for Software Development exam
|