ABAP Objects Interview Questions
Classes, interfaces, inheritance, polymorphism, events, exceptions and clean OO design—explained with practical ABAP examples.
What is ABAP Objects?
ABAP Objects is the object-oriented extension of ABAP. It groups state and behavior inside classes, creates objects as class instances, and supports encapsulation, single inheritance, interfaces and polymorphism. Local classes are available only inside their defining program; global classes are repository objects normally created in Class Builder or ABAP Development Tools.
1. Class, object and reference—what is the difference?
- Class: blueprint that declares attributes, methods, events, types and constants.
- Object: runtime instance of a class.
- Reference variable: typed handle that points to an object.
CLASS lcl_account DEFINITION FINAL.
PUBLIC SECTION.
METHODS constructor IMPORTING iv_balance TYPE decfloat34.
METHODS deposit IMPORTING iv_amount TYPE decfloat34.
METHODS get_balance RETURNING VALUE(rv_balance) TYPE decfloat34.
PRIVATE SECTION.
DATA mv_balance TYPE decfloat34.
ENDCLASS.
CLASS lcl_account IMPLEMENTATION.
METHOD constructor.
mv_balance = iv_balance.
ENDMETHOD.
METHOD deposit.
IF iv_amount > 0.
mv_balance += iv_amount.
ENDIF.
ENDMETHOD.
METHOD get_balance.
rv_balance = mv_balance.
ENDMETHOD.
ENDCLASS.
DATA(lo_account) = NEW lcl_account( iv_balance = 100 ).
lo_account->deposit( 50 ).
DATA(lv_balance) = lo_account->get_balance( ).
2. Explain PUBLIC, PROTECTED and PRIVATE sections
PUBLIC components form the external contract. PROTECTED components are available in the class and its subclasses. PRIVATE components are available only inside the class itself. Good design keeps mutable data private and exposes behavior through methods.
3. Instance versus static components
DATA, METHODS and EVENTS belong to each object instance. CLASS-DATA, CLASS-METHODS and CLASS-EVENTS belong to the class and can be accessed without creating an object. Avoid global mutable CLASS-DATA unless its lifecycle and concurrency implications are understood.
4. What does a constructor do?
The instance constructor is named CONSTRUCTOR and runs automatically when an object is created. It should establish valid object state. A static constructor named CLASS_CONSTRUCTOR runs once before the class is used for the first time and cannot have parameters.
5. Interface versus abstract class
| Interface | Abstract class |
|---|---|
| Defines a common contract; no instance can be created. | Can provide shared state and implemented methods. |
| A class can implement multiple interfaces. | ABAP supports only one direct superclass. |
| Ideal for loose coupling and polymorphism. | Useful when subclasses genuinely share implementation. |
INTERFACE lif_pricing.
METHODS calculate
IMPORTING iv_net TYPE decfloat34
RETURNING VALUE(rv_gross) TYPE decfloat34.
ENDINTERFACE.
CLASS lcl_standard_pricing DEFINITION FINAL.
PUBLIC SECTION.
INTERFACES lif_pricing.
ENDCLASS.
CLASS lcl_standard_pricing IMPLEMENTATION.
METHOD lif_pricing~calculate.
rv_gross = iv_net * CONV decfloat34( '1.18' ).
ENDMETHOD.
ENDCLASS.
DATA(lo_pricing) = NEW lcl_standard_pricing( ).
DATA(lo_contract) = CAST lif_pricing( lo_pricing ).
DATA(lv_gross) = lo_contract->calculate( 100 ).
6. What is inheritance in ABAP?
A subclass is declared with INHERITING FROM. It inherits components of one direct superclass, may add specialization and may redefine eligible instance methods. Use FINAL to prevent subclassing and ABSTRACT when a class is incomplete by design.
7. What is method redefinition?
A subclass declares an inherited method with REDEFINITION and supplies new implementation. Use super->method( ) when the parent behavior must be retained. The method signature remains unchanged.
8. Explain polymorphism with a project example
Polymorphism means code works with a general reference—often an interface—while runtime behavior depends on the concrete object. For example, an invoice service can depend on LIF_TAX_CALCULATOR and receive India, Germany or US implementations without IF/ELSE chains.
9. Up-casting and down-casting
Assigning a subclass reference to a superclass or implemented-interface reference is up-casting and is normally safe. Converting a general reference back to a more specific type is down-casting; use CAST or ?= only when the runtime object is compatible, otherwise a cast exception occurs.
10. What are events in ABAP Objects?
An event publisher declares an event and raises it using RAISE EVENT. A handler method is declared FOR EVENT ... OF ... and registered using SET HANDLER. This reduces direct coupling between publisher and subscribers.
11. How are class-based exceptions handled?
Create exception classes derived from CX_STATIC_CHECK, CX_DYNAMIC_CHECK or CX_NO_CHECK according to the contract. Raise with RAISE EXCEPTION TYPE or THROW, and handle using TRY/CATCH/CLEANUP. Prefer meaningful exception classes over return-code guessing.
TRY.
DATA(lv_result) = lo_service->execute( iv_id ).
CATCH zcx_business_error INTO DATA(lx_business).
MESSAGE lx_business->get_text( ) TYPE 'E'.
CATCH cx_root INTO DATA(lx_unexpected).
"Log unexpected technical error
ENDTRY.
12. Composition versus inheritance
Inheritance describes an “is-a” relationship; composition describes “has-a”. Prefer composition when behavior can be delegated to collaborators. It keeps hierarchies shallow, improves testability and lets implementations be swapped at runtime.
13. Local versus global classes
Use local classes for report-specific behavior, examples and focused ABAP Unit test doubles. Use global classes for reusable domain or application services. In modern development, keep public APIs small and depend on interfaces.
14. What is dependency injection in ABAP?
Dependencies are passed—commonly through the constructor or setter—instead of being created internally. This reduces coupling and makes ABAP Unit tests deterministic.
CLASS zcl_order_service DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
METHODS constructor IMPORTING io_repository TYPE REF TO zif_order_repository.
METHODS approve IMPORTING iv_order_id TYPE zorder_id.
PRIVATE SECTION.
DATA mo_repository TYPE REF TO zif_order_repository.
ENDCLASS.
METHOD constructor.
mo_repository = io_repository.
ENDMETHOD.
15. Common ABAP Objects interview traps
- Interfaces define contracts; they are not instantiated.
- ABAP class inheritance is single inheritance, although multiple interfaces can be implemented.
- Private components exist in inherited objects but are not visible to subclasses.
- Static state is shared and can create hidden coupling.
- Friendship gives selected users access to protected/private components and should be used sparingly.
- A final method cannot be redefined; a final class cannot be inherited.
Real project scenario
Strong answer: Define a small
ZIF_PAYMENT_PROCESSOR interface, implement one class per payment method, inject the interface into the orchestration service, map technical exceptions into business exceptions, and test orchestration with a test double. Avoid a growing CASE statement and avoid deep inheritance.Practical exercise
- Create
LIF_NOTIFICATIONwith methodSEND. - Implement email and in-app notification classes.
- Create a service that receives
REF TO LIF_NOTIFICATIONin its constructor. - Write one ABAP Unit test using a fake notifier and assert the sent message.
Rapid revision: 10 one-line answers
- Object = runtime instance of a class.
- Reference = typed handle to an object.
- Encapsulation = hide state, expose behavior.
- Interface = implementation-independent contract.
- ABAP supports one direct superclass.
- Polymorphism works through compatible superclass/interface references.
- Constructor establishes valid state.
- Events support publisher/subscriber communication.
- Composition is often safer than deep inheritance.
- Dependency injection improves testability.
Official SAP references
- SAP Help: ABAP Objects concept and examples
- SAP Help: ABAP Objects keywords
- SAP Help: Inheritance guideline
Previous: Part 4 — Open SQL and Performance | Next: Part 6 — Enhancements, BAdIs and User Exits
Disclaimer: Examples are educational. Validate release-specific behavior in your SAP system and current SAP documentation.
SAP ABAP INTERVIEW SERIES • PART 5
ABAP Objects Interview Questions
Classes, interfaces, inheritance, polymorphism, events, exceptions and clean OO design—explained with practical ABAP examples.
What is ABAP Objects?
ABAP Objects is the object-oriented extension of ABAP. It groups state and behavior inside classes, creates objects as class instances, and supports encapsulation, single inheritance, interfaces and polymorphism. Local classes are available only inside their defining program; global classes are repository objects normally created in Class Builder or ABAP Development Tools.
1. Class, object and reference—what is the difference?
- Class: blueprint that declares attributes, methods, events, types and constants.
- Object: runtime instance of a class.
- Reference variable: typed handle that points to an object.
CLASS lcl_account DEFINITION FINAL.
PUBLIC SECTION.
METHODS constructor IMPORTING iv_balance TYPE decfloat34.
METHODS deposit IMPORTING iv_amount TYPE decfloat34.
METHODS get_balance RETURNING VALUE(rv_balance) TYPE decfloat34.
PRIVATE SECTION.
DATA mv_balance TYPE decfloat34.
ENDCLASS.
CLASS lcl_account IMPLEMENTATION.
METHOD constructor.
mv_balance = iv_balance.
ENDMETHOD.
METHOD deposit.
IF iv_amount > 0.
mv_balance += iv_amount.
ENDIF.
ENDMETHOD.
METHOD get_balance.
rv_balance = mv_balance.
ENDMETHOD.
ENDCLASS.
DATA(lo_account) = NEW lcl_account( iv_balance = 100 ).
lo_account->deposit( 50 ).
DATA(lv_balance) = lo_account->get_balance( ).
2. Explain PUBLIC, PROTECTED and PRIVATE sections
PUBLIC components form the external contract. PROTECTED components are available in the class and its subclasses. PRIVATE components are available only inside the class itself. Good design keeps mutable data private and exposes behavior through methods.
3. Instance versus static components
DATA, METHODS and EVENTS belong to each object instance. CLASS-DATA, CLASS-METHODS and CLASS-EVENTS belong to the class and can be accessed without creating an object. Avoid global mutable CLASS-DATA unless its lifecycle and concurrency implications are understood.
4. What does a constructor do?
The instance constructor is named CONSTRUCTOR and runs automatically when an object is created. It should establish valid object state. A static constructor named CLASS_CONSTRUCTOR runs once before the class is used for the first time and cannot have parameters.
5. Interface versus abstract class
| Interface | Abstract class |
|---|---|
| Defines a common contract; no instance can be created. | Can provide shared state and implemented methods. |
| A class can implement multiple interfaces. | ABAP supports only one direct superclass. |
| Ideal for loose coupling and polymorphism. | Useful when subclasses genuinely share implementation. |
INTERFACE lif_pricing.
METHODS calculate
IMPORTING iv_net TYPE decfloat34
RETURNING VALUE(rv_gross) TYPE decfloat34.
ENDINTERFACE.
CLASS lcl_standard_pricing DEFINITION FINAL.
PUBLIC SECTION.
INTERFACES lif_pricing.
ENDCLASS.
CLASS lcl_standard_pricing IMPLEMENTATION.
METHOD lif_pricing~calculate.
rv_gross = iv_net * CONV decfloat34( '1.18' ).
ENDMETHOD.
ENDCLASS.
DATA(lo_pricing) = NEW lcl_standard_pricing( ).
DATA(lo_contract) = CAST lif_pricing( lo_pricing ).
DATA(lv_gross) = lo_contract->calculate( 100 ).
6. What is inheritance in ABAP?
A subclass is declared with INHERITING FROM. It inherits components of one direct superclass, may add specialization and may redefine eligible instance methods. Use FINAL to prevent subclassing and ABSTRACT when a class is incomplete by design.
7. What is method redefinition?
A subclass declares an inherited method with REDEFINITION and supplies new implementation. Use super->method( ) when the parent behavior must be retained. The method signature remains unchanged.
8. Explain polymorphism with a project example
Polymorphism means code works with a general reference—often an interface—while runtime behavior depends on the concrete object. For example, an invoice service can depend on LIF_TAX_CALCULATOR and receive India, Germany or US implementations without IF/ELSE chains.
9. Up-casting and down-casting
Assigning a subclass reference to a superclass or implemented-interface reference is up-casting and is normally safe. Converting a general reference back to a more specific type is down-casting; use CAST or ?= only when the runtime object is compatible, otherwise a cast exception occurs.
10. What are events in ABAP Objects?
An event publisher declares an event and raises it using RAISE EVENT. A handler method is declared FOR EVENT ... OF ... and registered using SET HANDLER. This reduces direct coupling between publisher and subscribers.
11. How are class-based exceptions handled?
Create exception classes derived from CX_STATIC_CHECK, CX_DYNAMIC_CHECK or CX_NO_CHECK according to the contract. Raise with RAISE EXCEPTION TYPE or THROW, and handle using TRY/CATCH/CLEANUP. Prefer meaningful exception classes over return-code guessing.
TRY.
DATA(lv_result) = lo_service->execute( iv_id ).
CATCH zcx_business_error INTO DATA(lx_business).
MESSAGE lx_business->get_text( ) TYPE 'E'.
CATCH cx_root INTO DATA(lx_unexpected).
"Log unexpected technical error
ENDTRY.
12. Composition versus inheritance
Inheritance describes an “is-a” relationship; composition describes “has-a”. Prefer composition when behavior can be delegated to collaborators. It keeps hierarchies shallow, improves testability and lets implementations be swapped at runtime.
13. Local versus global classes
Use local classes for report-specific behavior, examples and focused ABAP Unit test doubles. Use global classes for reusable domain or application services. In modern development, keep public APIs small and depend on interfaces.
14. What is dependency injection in ABAP?
Dependencies are passed—commonly through the constructor or setter—instead of being created internally. This reduces coupling and makes ABAP Unit tests deterministic.
CLASS zcl_order_service DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
METHODS constructor IMPORTING io_repository TYPE REF TO zif_order_repository.
METHODS approve IMPORTING iv_order_id TYPE zorder_id.
PRIVATE SECTION.
DATA mo_repository TYPE REF TO zif_order_repository.
ENDCLASS.
METHOD constructor.
mo_repository = io_repository.
ENDMETHOD.
15. Common ABAP Objects interview traps
- Interfaces define contracts; they are not instantiated.
- ABAP class inheritance is single inheritance, although multiple interfaces can be implemented.
- Private components exist in inherited objects but are not visible to subclasses.
- Static state is shared and can create hidden coupling.
- Friendship gives selected users access to protected/private components and should be used sparingly.
- A final method cannot be redefined; a final class cannot be inherited.
Real project scenario
Strong answer: Define a small
ZIF_PAYMENT_PROCESSOR interface, implement one class per payment method, inject the interface into the orchestration service, map technical exceptions into business exceptions, and test orchestration with a test double. Avoid a growing CASE statement and avoid deep inheritance.Practical exercise
- Create
LIF_NOTIFICATIONwith methodSEND. - Implement email and in-app notification classes.
- Create a service that receives
REF TO LIF_NOTIFICATIONin its constructor. - Write one ABAP Unit test using a fake notifier and assert the sent message.
Rapid revision: 10 one-line answers
- Object = runtime instance of a class.
- Reference = typed handle to an object.
- Encapsulation = hide state, expose behavior.
- Interface = implementation-independent contract.
- ABAP supports one direct superclass.
- Polymorphism works through compatible superclass/interface references.
- Constructor establishes valid state.
- Events support publisher/subscriber communication.
- Composition is often safer than deep inheritance.
- Dependency injection improves testability.
Official SAP references
- SAP Help: ABAP Objects concept and examples
- SAP Help: ABAP Objects keywords
- SAP Help: Inheritance guideline
Previous: Part 4 — Open SQL and Performance | Next: Part 6 — Enhancements, BAdIs and User Exits
Disclaimer: Examples are educational. Validate release-specific behavior in your SAP system and current SAP documentation.

0 Comments