What is the difference between a class and an object in ABAP Objects, and what actually happens when you write NEW?
Say your answer out loud first.
Practise another way
A class is the template: it declares attributes, methods and events, globally in the class library or locally in a program. An object is one instance of that class, created at runtime in the internal session, and I only reach it through a reference variable.
NEW creates the object, runs its constructor and returns the reference. Two variables can point to the same object, and once no reference is left, the garbage collector removes it.
Class: the definition. It declares components (attributes with DATA/CLASS-DATA, methods, events, implemented interfaces) in visibility sections, and the implementation part holds the method code.
A global class lives in the class library (ADT, or SE24 in classic systems); a local class lives inside one program or class pool. In ABAP Cloud you create classes in ABAP Development Tools only.
Object: one instance of a class. All instances share the same structure but carry their own values for instance attributes. Objects exist only at runtime, inside the internal session of the program that created them.
What NEW does
- Creates the object in the internal session.
- On the first use of the class in that session, runs the static constructor first.
- Runs the instance constructor with the parameters you pass.
- Returns a reference, which you keep in an object reference variable.
CLASS lcl_invoice DEFINITION FINAL CREATE PUBLIC.
PUBLIC SECTION.
METHODS constructor IMPORTING amount TYPE decfloat34.
METHODS get_amount RETURNING VALUE(result) TYPE decfloat34.
PRIVATE SECTION.
DATA amount TYPE decfloat34.
ENDCLASS.
CLASS lcl_invoice IMPLEMENTATION.
METHOD constructor.
me->amount = amount.
ENDMETHOD.
METHOD get_amount.
result = amount.
ENDMETHOD.
ENDCLASS.
" in a caller's method
DATA(first) = NEW lcl_invoice( 100 ).
DATA(second) = NEW lcl_invoice( 250 ). " same class, own state
DATA(same) = first. " copies the reference only
CLEAR first. " object 100 lives on via same
Points interviewers check
- You never touch an object directly, only through references.
same = firstcopies the reference, not the object. - When no reference points to an object any more, the garbage collector frees it; ABAP has no destructor you call.
meis the self-reference inside instance methods; static components belong to the class and are reached withclass=>component.- Every class without
INHERITING FROMis implicitly a subclass of the empty abstract root classOBJECT. - Prefer
NEWtoCREATE OBJECT; you still needCREATE OBJECT ... TYPE (name)for dynamic class names.
To try it, implement IF_OO_ADT_CLASSRUN in a global class and run it with F9 in ADT. This works the same in SAP S/4HANA and in the ABAP environment of SAP Business AI Platform (formerly SAP BTP).
Separates design time (class) from runtime (object), explains references, NEW, the constructor and garbage collection, and shows two references to one object.
Says 'a class is a blueprint and an object is a real thing' and stops, with no idea of references or object lifetime.
Thinking an assignment between reference variables copies the object. It copies the reference, so a change through one variable is visible through the other.
- What happens to an object when you CLEAR the only reference to it?
- When do you still need CREATE OBJECT?
- What is the root class of every ABAP class?
- Where do static attributes live compared with instance attributes?
1 candidate write-up, 2 official pages and 2 prep guides. Confidence: high. Checked 1 Dec 2026.
- Prep guide Gives the question.
- Candidate write-up Gives the question.
- Prep guide Gives the question.
- Official page Backs the answer.
- Official page Backs the answer.