Ads

SAP ABAP Object oriented programming Interview Questions and Answers

SAP ABAP Object oriented programming Interview Questions and Answers

These Object-oriented programming Interview Questions and Answers are useful for Freshers and Experienced ABAP Consultants.

what are Exception Classes in Object-Oriented Programming?


Definition:
Exceptions are the errors that occur during the execution of the program that interrupts the normal flow of control.

Types of Exceptions:


All exception classes are inherited from global class CX_ROOT and the classes that are directly inherited are

CX_STATIC_CHECK:
It is checked by both the compiler and runtime system. If any exception of this category found and not handled locally inside the procedure, it has been declared in the RAISING clause of the procedure’s interface

CX_DYNAMIC_CHECK:
It is checked only at runtime system. when the excetions tries to leave a procedure that it has been declared in RAISING class. Generally all system exceptions like CX_SY_ZERO_DIVIDE will come under these exceptions

CX_NO_CHECK:
This type of exceptions will be choosenif the exeception can occur almost everywhere. These exceptions are always implicitly declared.
Neither the compiler nor the runtime system performs any interface checks.
Step-by-Step Approach for creation of Exception Classes
DATA: ex_ref TYPE REF TO cx_root.
DATA: message_text TYPE string.

TRY.
    RAISE EXCEPTION TYPE zcx_excep_cls
                EXPORTING msgv1 = 'For'
                                      msgv2 = 'Handling'
                                      msgv3 = 'Exceptions '
                                      msgv4 = 'In Program '.

  CATCH zcx_excep_cls INTO ex_ref.
    message_text = ex_ref->get_text( ).
    WRITE message_text.
ENDTRY. 

How do you Redefine methods in subclass

Definition: The methods of the super class can be re-implemented at the sub class.  
Purpose to redefine methods: if the method implementation at the super class is not satisfies the requirement of the object which is created with reference to the sub class.
Principles of redefining methods:  
1. The REDEFINITION statement for the inherited method must be in the same SECTION as the definition of the original method.
2. If you redefine a method, you do not need to enter its interface again in the subclass, but only the name of the method.
3. In the case of redefined methods, changing the interface (overloading) is not permitted; exception: Overloading is possible with the constructor
4. Within the redefined method, you can access components of the direct super class using the SUPER reference.
5. The pseudo-reference super can only be used in redefined methods.

What is Use of final class?

Final Classes and Methods in Object Oriented Programming

Final Class: A class that is defined as final class can not be inherited further. All Methods of a final class are inherently final and must not be declared as final in the class definition. Also a final method can not be redefined further.
If only a method of a class is final then that class can be inherited but that method cannot be redefined.

 If you don't want anyone else to change or override the functionality of your class then you can define it as final. Thus no one can inherit and modify the features of this class.  

What is Event Handler Technique in Object oriented ABAP?


Event is a mechanism by which method of one class can raise method of another class, without the hazard of instantiating that class. It provides to raise the method (event handler method) of one class with help of another method in the same or different class (triggering method).
The below steps is required to have the event handler in the class:-
Create an event in a class.
Create a triggering method in the same class which will raise the event. 
Create an event handler method for the event in same/other class. 
Register the event handler method in the program. 
Now, the above settings are complete for event handler in class. Create an object from the class containing the event and call the triggering method to raise the event.

What is Narrow Casting?


Definition: The assignment of a subclass instance to a reference variable of the type "reference to super class" is described as a narrowing cast, because you are switching from a more detailed view to a one with less detail. It is also called as up-casting.  
Use of narrowing casting:
A user who is not interested in the finer points of cars, trucks, and busses (but only, for example, in the fuel consumption and tank gauge) does not need to know about them. This user only wants and needs to work with (references to) the lcl_vehicle(super class) class. However, in order to allow the user to work with cars, busses, or trucks, you generally need a narrowing cast.  
Principle of narrowing casting:
1. In narrowing casting the object which is created with reference to the sub class is assigned to the reference of type super class.
2. Using the super class reference it is possible to access the methods from the object which are only defined at the super class.
3. This access is also called as generic access as super class is normally called as general class.  
Example:

 What are Abstract Classes and Methods in Object Oriented Programming?


Abstract Class:  Classes which contain one or more abstract methods or abstract properties, such methods or properties do not provide implementation. These abstract methods or properties are implemented in the derived classes (Sub-classes).  
Abstract classes does not create any instances to that class objects  

Use of Abstract class:
We can define some common functionality in Abstract class (Super-class) and those can be used in derived classes (Sub classes).  

What are Interfaces?

 ABAP interfaces are implemented in addition to, and independently of classes. An interface only has a declaration part, and do not have visibility sections. Components (Attributes, methods, constants, types) can be defined the same way as in classes.
•Interfaces are listed in the definition part of the class, and must always be in the    PUBLIC SECTION.
•Operations defined in the interface are implemented as methods of the class. All methods of the interface must be present in the implementation part of the class.
•Attributes, events, constants and types defined in the interface are automatically available to the class carrying out the implementation.
•Interface components are addressed in the class by <interface name>~<component name>

What is   SUPER Keyword in object Oriented Programming?

SUPER is the key word used to represent the super class of a class in oops you can access the methods and attributes of the super class using this word SUPER. 


What are Components of a Class ?

Attributes:-  Any data,constants,types declared within a class form the attribute of the class.
Methods:-  Block of code, providing some functionality offered by the class. Can be compared to function modules. They can access all of the attributes of a class.
Methods are defined in the definition part of a class and implement it in the implementation part using the following processing block:
 METHOD <meth>.
                   ...
                 ENDMETHOD
Methods are called using the CALL METHOD statement.
Events:-  A mechanism set within a class which can help a class to trigger methods of other class.
Interfaces:- Interfaces are independent structures that you can implement in a class to extend the scope of that class.

 What are Instance and Static Components?

Instance components exist separately in each instance (object) of the class and are referred using instance component selector using =>’.

Static components only exist once per class and are valid for all instances of the class. They are declared with the CLASS- keywords

Static components can be used without even creating an instance of the class and are referred to using static component selector  . 

What is Visibility of Component?

Each class component has a visibility. In ABAP Objects the whole class definition is separated into three visibility sections: PUBLIC, PROTECTED, and PRIVATE.

1) Data declared in public section can be accessed by the class itself, by its sub-classes as well as by other users outside the class.
2) Data declared in the protected section can be accessed by the class itself,  and also by its sub-classes but not by external users outside the class.
3) Data declared in the private section can be accessed by the class only, but not by its sub-classes and by external users outside the class.

What is abstraction,encapsulation and polymorphism?

Abstraction: Everything is visualized in terms of classes and objects.


Encapsulation The wrapping up of data and methods into a single unit (called class) is known as Encapsulation. The data is not accessible to the outside world only those methods, which are wrapped in the class, can access it.

Polymorphism: Methods of same name behave differently in different classes. Identical(identically-named) methods behave differently in different classes. Object-oriented programming contains constructions called interfaces. They enable you to address methods with the same name in different objects. Although the form of address is always the same, the implementation of the method is specific to a particular class.

What are instance and static components?

Instance components : These components exist separately in each instance (object) of the class and are referred using instance component selector using ->
Static components : These components exists globally for a class and are referred to using static component selector => .


What is  Widening Cast?

When we assign the instance of the Superclass to the Subclass, than it is called the Widening Cast, because we are moving to the “More Specific View” from the “Less specific view”. Everytime it is not possible to move the Superclass reference to the Subclass,
ABAP    Objects         Concepts – Friends

What is FRIENDS keyword?

In any Object Oriented programming language, the access to private or protected components – both methods and attributes – would be prohibited. If someone try to access them, compiler would generate syntax error.
Sometimes, it would be advantageous to give the access to these protected and private attributes to other classes. This can be achieved using the FRIENDS addition.

What is a constructor in a class ?

CONSTRUCTOR is a special type of method, it is executed automatically whenever a object is created or instantiated.
These methods are mainly used to set default values in classes.
CONSTRUCTORS are two types in SAP classes.
1.CONSTRUCTOR (Instance Constructor).
2.CLASS CONSTRUCTOR (Static Constructor).


CONSTRUCTOR.

These methods can only have importing parameters, there will not be any exporting parameters.
The name of the CONSTRUCTOR method must be CONSTRUCTOR only.


CLASS CONSTRUCTOR (Also called as STATIC CONSTRUCTOR).


It is a type of constructor, this method will be executed automatically whenever a first call to the class is made, the first call may be through instance or through class.
These CLASS CONSTRUCTORS are mainly used to values globally set the default i:e irrespective of instances, these methods will not have any importing and exporting parameters.These methods will be executed only once.
Name of the CLASS CONSTRUCTOR must be CLASS_CONSTRUCTOR.

What is SINGLETON CLASSES?


Often, there is a requirement that you would want to create only one instance of the class. To put it in other words, you do not want anyone to create instance of the class if already created. This is a common requirement in many application designs. So how do we achieve this?
This can be achieved using the singleton pattern. In this design pattern, we will declare the constructor as a 'Private' one. Private constructor!! Is that possible?
Yes, it is.
Go to the properties tab of class builder (SE24) and change the instantiation type to private. Then you can create a private constructor. The advantage of having a private constructor is that now no one can create an object of your class.. 

So how do we create the instance of this class ? We create a static method GET_INSTANCE that will be used to create the instance. A static method because this method can be called directly with the class reference (without an object). Inside this method, we can create the object (because the constructor is a private method, we can call it within class). 

Now, how to make sure that only one instance is created? Simple.
Store the own reference as an attribute of the class. In the method GET_INSTANCE check if this attribute is populated. If it populated then return the same instance. If not, create a new one, store it in the own attribute and return the instance.
An example implementation of GET_INSTANCE is shown here. Lets say the name of the attribute is GREF_OBJ.
IF gref_obj IS INITIAL.CREATE OBJECT gref_obj TYPE (class name).
ENDIF.

RETURN gref_obj.
An example how to create the instance of the class is shown here:
lref_obj = (class_name)=>get_instance_of().
 Creating Attributes  
Attributes contain data. They define the state of an object, that is the instance of a class.
Prerequisites
You must already have created the internal data types in the class to which you want to refer when you create the attributes. See also :Creating Internal Types in Classes.
Procedure
1. Select the class or interface and change to the Class Editor.
2. Choose Attributes.
3. To create an attribute, make the following entries:

- Attribute

Define a unique name with which the attribute is identified. Remember to observe the naming conventions in ABAP Objects.

- Type

You can specify an attribute as a constant, an instance attribute, or a static attribute (that is shared by all instances of the class).

- Visibility

Define the visibility of attributes for the user of the class. Public assigns the attribute to the public area of the class and the attribute can be called by every user of the class. Remember that public attributes form part of the external point of contact to the class, and as such stand in the way of full encapsulation.
Attributes that are protected are visible and can be used by the class itself and any of its subclasses. 
Attributes that are private are only visible in and available to the class itself. Private attributes therefore are not visible in the subclasses.

- Modeled only

If you have selected this option, the system does not enter the interface in the class pool. You cannot access the components at run time. 

- Typing method

ABAP keyword for defining the type reference. You can choose one of the following: Type, Like or Type Ref To (for class references).

- Reference type

You can use any elementary ABAP type (including generic types) or object type (classes and interfaces).

- Read-Only

This option restricts the changeability of attributes as well as visibility. Users cannot change the attribute if a flag is set. 

- Description

Short description of the components.

- Initial value

You must enter an initial value for constants.


How do Create and Define Methods ? 

Methods describe how an object behaves. You implement them using functions defined within classes. They are operations that change the attributes of a class or interface. There are instance- and static methods. Instance methods refer to a certain class instance, whereas static methods are common to all the class instances. Static methods can only address static attributes.
The special methods include constructors and class constructors. Constructors (class constructors) need not be created explicitly if they are not to be implemented.
Prerequisites
You must already have created the class or interface. It is useful if you have already created the attributes of the class, since you can branch directly from a method definition in the Class Builder to its implementation.
Procedure
To create methods for classes and interfaces:
1. Change to the Class Editor.
2. Choose Methods.
3. To create a method, make the following entries:

- Methods
Define a unique name with which the method is identified. 
Remember to observe the naming conventions for ABAP Objects.

- Type
Specifies the type as an instance method or a static method (not instance-specific).

- Visibility
Define the visibility of methods for the user of the class. Public assigns the method to the public area of the class and the method can be called by every user of the class. If you make the method protected, it is visible to and can be used by the class itself and any of its subclasses. If the method is private, it is only visible in and available to the class itself. Private methods do not form part of the external point of contact between the class and its users.

- Modeled only
If the flag is set, no entry will be made in the class pool. You cannot access the components at runtime. 

- Description
Short description of the method.
4. Repeat the above steps for any further methods.


If you create a constructor or class constructor method, it is assigned the predefined name CONSTRUCTOR or CLASS_CONSTRUCTOR respectively. The Class Builder also predefines certain other attributes. 

How do you Create Standard Classes ? 

To create a new class from the initial screen of the ABAP Workbench:
1. Enter the name of the new class according to the naming conventions under Object type.
2. Choose Create.
The Create Class dialog box appears with the name of the class:
3. Enter the following details for the subclass definition:
- Class
Name of the new class.
   Create Inheritance
When you choose this function, the Inherits from dialog box appears. You can define the inheritance relationship here by specifying the name of the superclass. 
You can define the superclass as any class from the class library that is not defined as final.
- Description
A short text describing the new class.
- Inst. Creation
In general, classes are marked with the Public option. This means that each user can create instances of the particular class (with CREATE OBJECT). 
The Protected option defines that only inherited classes or the relevant class itself can create instances of this class. 
If you choose the Private option, only the relevant class itself can create its instances (only using its own method). 
You can define an abstract class with the Abstract option. You cannot create an instance for this class. An abstract class can be used as template for your subclasses. You can only access this class with your static attributes or with your subclasses.

- Class type
You define the basic type and use of the class here. Copy the entry Normal ABAP class. You can also choose Exception class orPersistent class. You can find more information about these special classes under:
Defining Exception Classes
Defining Persistent Classes
- Final
You define a final class with the Final option. This class completes the inheritance hierarchy since a final class may not create any further subclasses.
If an abstract class is also defined as final. This is advisable if you only want to access the static components of this class.
- Modeled only
If you select this option, the class is not included in the class pool. You will not be able to address it at runtime or test it.
4. Choose  Save.
The Create Object Catalog Entry dialog box is displayed.
5. Enter the Package.
6. Choose Save.
The method display of the Class Editor appears. From here, you can define its components and include interfaces in it.
Object Handling  
Objects
Objects are instances of classes. Each object has a unique identity and its own attributes. All transient objects reside in the context of an internal session (memory area of an ABAP program). Persistent objects in the database are not yet available. A class can have any number of objects (instances).
Object References
To access an object from an ABAP program, you use object references. Object references are pointers to objects. In ABAP, they are always contained in reference variables.
Reference variables
Reference variables contain references. A reference variable is either initial or contains a reference to an existing object. The identity of an object depends on its reference. A reference variable that points to an object knows the identity of that object. Users cannot access the identity of the object directly.
Reference variables in ABAP are treated like other elementary data objects. This means that a reference variable can occur as a component of a structure or internal table as well as on its own.
Data Types for References
ABAP contains a predefined data type for references, comparable to the data types for structures or internal tables. The full data type is not defined until the declaration in the ABAP program. The data type of a reference variable determines how the program handles its value (that is, the object reference). There are two principal types of references: Class references and interface references (seeInterfaces).
You define class references using the
... TYPE REF TO <class>
addition in the TYPES or DATA statement, where <class> refers to a class. A reference variable with the type class reference is called a class reference variable, or class reference for short.
A class reference <cref> allows a user to create an instance (object) of the corresponding class, and to address a visible component <comp> within it using the form
cref->comp
Creating Objects
Before you can create an object for a class, you need to declare a reference variable with reference to that class. Once you have declared a class reference variable <obj> for a class <class>, you can create an object using the statement
CREATE OBJECT <cref>.
This statement creates an instance of the class <class>, and the reference variable <cref> contains a reference to the object.
Addressing the Components of Objects
Programs can only access the instance components of an object using references in reference variables. The syntax is as follows (where <ref> is a reference variable):
To access an attribute <attr>: <ref>-><attr>
To call a method <meth>: CALL METHOD <ref>-><meth>
You can access static components using the class name as well as the reference variable. It is also possible to address the static components of a class before an object has been created.
Addressing a static attribute <attr>: <class>=><attr>
Calling a static method <meth>: CALL METHOD <class>=><meth>
Within a class, you can use the self-reference ME to access the individual components:
To access an attribute <attr> in the same class: ME-><attr>
To call a method <meth> in the same class: CALL METHOD ME-><meth>
Self references allow an object to give other objects a reference to it. You can also access attributes in methods from within an object even if they are obscured by local attributes of the method.
Creating More Than One Instance of a Class
In a program, you can create any number of objects from the same class. The objects are fully independent of each other. Each one has its own identity within the program and its own attributes. Each CREATE OBJECT statement generates a new object, whose identity is defined by its unique object reference.
Assigning References
You can assign references to different reference variables using the MOVE statement. In this way, you can make the references in several reference variables point to the same object. When you assign a reference to a different reference variable, their types must be either compatible or convertible.
When you use the MOVE statement or the assignment operator (=) to assign reference variables, the system must be able to recognize in the syntax check whether an assignment is possible. The same applies when you pass reference variables to procedures as parameters. If you write the statement
<cref1> = <cref2>
the two class references <cref1> and <cref2> must have the same type, that is, they must either refer to the same class, or the class of <cref1> must be the predefined empty class OBJECT. The class OBJECT has no components, and has the same function for reference variables as the data type ANY has for normal variables. Reference variables with the type OBJECT can function as containers for passing references. However, you cannot use them to address objects.
Object Lifetime
An object exists for as long as it is being used in the program. An object is in use by a program for as long as at least one reference points to it, or at least one method of the object is registered as an event handler.
As soon as there are no more references to an object, and so long as none of its methods are registered as event handlers, it is deleted by the automatic memory management (garbage collection). The ID of the object then becomes free, and can be used by a new object.


What is Object Orientation?  

Object orientation (OO), or to be more precise, object-oriented programming, is a problem-solving method in which the software solution reflects objects in the real world.
A comprehensive introduction to object orientation as a whole would go far beyond the limits of this introduction to ABAP Objects. This documentation introduces a selection of terms that are used universally in object orientation and also occur in ABAP Objects. In subsequent sections, it goes on to discuss in more detail how these terms are used in ABAP Objects. The end of this section contains a list of further reading, with a selection of titles about object orientation.

Objects

An object is a section of source code that contains data and provides services. The data forms the attributes of the object. The services are known as methods (also known as operations or functions). Typically, methods operate on private data (the attributes, or state of the object), which is only visible to the methods of the object. Thus the attributes of an object cannot be changed directly by the user, but only by the methods of the object. This guarantees the internal consistency of the object.

Classes

Classes describe objects. From a technical point of view, objects are runtime instances of a class. In theory, you can create any number of objects based on a single class. Each instance (object) of a class has a unique identity and its own set of values for its attributes.

Object References

In a program, you identify and address objects using unique object references. Object references allow you to access the attributes and methods of an object.
In object-oriented programming, objects usually have the following properties:

Encapsulation

Objects restrict the visibility of their resources (attributes and methods) to other users. Every object has an interface, which determines how other objects can interact with it. The implementation of the object is encapsulated, that is, invisible outside the object itself.

Polymorphism

Identical (identically-named) methods behave differently in different classes. Object-oriented programming contains constructions called interfaces. They enable you to address methods with the same name in different objects. Although the form of address is always the same, the implementation of the method is specific to a particular class.

Inheritance

You can use an existing class to derive a new class. Derived classes inherit the data and methods of the superclass. However, they can overwrite existing methods, and also add new ones.


Declaring Methods


You can declare methods in the declaration part of a class or in an interface. To declare instance methods, use the following statement:
METHODS <meth> IMPORTING.. [VALUE(]<ii>[)] TYPE type [OPTIONAL].. 
               EXPORTING.. [VALUE(]<ei>[)] TYPE type [OPTIONAL].. 
               CHANGING.. [VALUE(]<ci>[)] TYPE type [OPTIONAL].. 
               RETURNING VALUE(<r>) 
               EXCEPTIONS.. <ei>..
and the appropriate additions.
To declare static methods, use the following statement:
CLASS-METHODS <meth>...
Both statements have the same syntax.
When you declare a method, you also define its parameter interface using the additions IMPORTING, EXPORTING, CHANGING, and RETURNING. The additions define the input, output, and input/output parameters, and the return code. They also define the attributes of the interface parameters, namely whether a parameter is to be passed by reference or value (VALUE), its type (TYPE), and whether it is optional (OPTIONAL, DEFAULT). Unlike in function modules, the default way of passing a parameter in a method is by reference. To pass a parameter by value, you must do so explicitly using the VALUE addition. The return value (RETURNING parameter) must always be passed explicitly as a value. This is suitable for methods that return a single output value. 

If you use it, you cannot use EXPORTING or CHANGING parameters.
As in function modules, you can use exception parameters (EXCEPTIONS) to allow the user to react to error situations when the method is executed.

Implementing Methods


You must implement all of the methods in a class in the implementation part of the class in a
METHOD <meth>.
 ...
ENDMETHOD.
block. When you implement the method, you do not have to specify any interface parameters, since these are defined in the method declaration. The interface parameters of a method behave like local variables within the method implementation. You can define additional local variables within a method using the DATA statement.

As in function modules, you can use the RAISE <exception> and MESSAGE RAISING statements to handle error situations.

When you implement a static method, remember that it can only work with the static attributes of your class. Instance methods can work with both static and instance attributes.

Calling Methods


To call a method, use the following statement:
CALL METHOD <meth> EXPORTING... <ii> =.<f i>... 
                   IMPORTING... <ei> =.<g i>... 
                   CHANGING ... <ci> =.<f i>... 
                   RECEIVING         r = h 
                   EXCEPTIONS... <ei> = rc i...
The way in which you address the method <method> depends on the method itself and from where you are calling it. Within the implementation part of a class, you can call the methods of the same class directly using their name <meth>.

CALL METHOD <meth>...

Outside the class, the visibility of the method depends on whether you can call it at all. Visible instance methods can be called from outside the class using

CALL METHOD <ref>-><meth>...

where <ref> is a reference variable whose value points to an instance of the class. Visible instance methods can be called from outside the class using

CALL METHOD <class>=><meth>...

where <class> is the name of the relevant class.

When you call a method, you must pass all non-optional input parameters using the EXPORTING or CHANGING addition in the CALL METHOD statement. You can (but do not have to) import the output parameters into your program using the IMPORTING or RECEIVING addition. Equally, you can (but do not have to) handle any exceptions triggered by the exceptions using the EXCEPTIONS addition. However, this is recommended.

You pass and receive values to and from methods in the same way as with function modules, that is, with the syntax:
... <Formal parameter> = <Actual parameter>
after the corresponding addition. The interface parameters (formal parameters) are always on the left-hand side of the equals sign. The actual parameters are always on the right. The equals sign is not an assignment operator in this context; it merely serves to assign program variables to the interface parameters of the method.

If the interface of a method consists only of a single IMPORTING parameter, you can use the following shortened form of the method call:

CALL METHOD <method>( f).

The actual parameter <f> is passed to the input parameters of the method.
If the interface of a method consists only of IMPORTING parameters, you can use the following shortened form of the method call:

CALL METHOD <method>(....<ii> =.<f i>...).

Each actual parameter <f i > is passed to the corresponding formal parameter <i i >.


Event Handler Methods

Event handler methods are special methods that cannot all be called using the CALL METHOD statement. Instead, they are triggered using events. You define a method as an event handler method using the addition
... FOR EVENT <evt> OF <cif>...
in the METHODS or CLASS-METHODS statement.
The following special rules apply to the interface of an event handler method:
The interface may only consist of IMPORTING parameters.
Each IMPORTING parameter must be an EXPORTING parameter of the event <evt>.
The attributes of the parameters are defined in the declaration of the event <evt> (EVENTS statement) and are adopted by the event handler method.
See also Triggering and Handling Events

Constructors


Constructors are special methods that cannot be called using CALL METHOD. Instead, they are called automatically by the system to set the starting state of a new object or class. There are two types of constructors - instance constructors and static constructors. Constructors are methods with a predefined name. To use them, you must declare them explicitly in the class.
The instance constructor of a class is the predefined instance method CONSTRUCTOR. You declare it in the public section as follows:

METHODS CONSTRUCTOR 
        IMPORTING.. [VALUE(]<ii>[)] TYPE type [OPTIONAL].. 
        EXCEPTIONS.. <ei>.
and implement it in the implementation section like any other method. The system calls the instance constructor once for each instance of the class, directlyafter the object has been created in the CREATE OBJECT statement. You can pass the input parameters of the instance constructor and handle its exceptions using the EXPORTING and EXCEPTIONS additions in the CREATE OBJECT statement.

The static constructor of a class is the predefined static method CLASS_CONSTRUCTOR. You declare it in the public section as follows:
CLASS-METHODS CLASS_CONSTRUCTOR.
and implement it in the implementation section like any other method. The static constructor has no parameters. The system calls the static constructor once for each class before the class is accessed for the first time. The static constructor cannot, therefore, access the components of its own class.

Object-oriented programming Interview Questions and Answers, Object-oriented programming, OOPs, SAP ABAP, Interview Questions.

Comments

Post a Comment

Popular posts from this blog

BADI Interview Questions in SAP ABAP

Sample SAP ABAP Programming Examples for Practice

Module Pool Programming Interview Questions and Answers in SAP ABAP

Step by Step tutorial on BDC Session Method Program in SAP ABAP

SAP ABAP Interview Questions and Answers for 10 Years Experienced