OOPS ABAP Interview Questions and Answers
by Bharathkumar, on Sep 10, 2022 11:06:53 PM
1. What is OOPS ABAP ?
- 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.
2. Is It Mandatory To Implement All Methods Of Interface In The Class Which Includes Interface?
No it is not mandatory to implement all normal interface methods but it is mandatory to implement all Abstract methods.
3.What Is An Interface In Ooabap?
Interface is class which contains methods without implementations.
4.Can We Instantiate The Interface?
No, we can not instantiate interface using create object keyword.
5.Can We Achieve Multiple Inheritance Using Interfaces?
Yes, by using interface concept in SAP ABAp, we can achieve multiple inheritance
6.Does Polymorphism Achieved Through Interfaces?
Yes, by using interface concept in SAP ABAP, we can polymorphism
7.What Is The Difference Between Abstract Class And Interface?
Abstract class is a class which contains at least one abstract method( Method without implementation), Abstract class contains methods with implementation and without implementation and we cannot create instance for the abstract class .
- Abstract class is mainly for inheritance .
- Interface contains methods without implementation .
8.What Is Alias Name In Ooabap?
Alias is an alias name for the interface method implemented in the class .
9.Can We Raise Events In Interface?
No, you can not raise events in interface, Because there is no Implementation for the methods. We can create events in interfaces .
10.What Is A Single-ton Class?
Single-ton class is a class which allows to instantiate once only .
11.What Is The Difference In Attributes Defined In The Public Versus Private Section Of A Class?
Public attributes can be accessed by class, subclasses and other classes where as Private attributes can be accessed by class itself only.
12.What is the Difference between Class and Object ?
A Class is actually a blueprint or a template to create an Object. Whereas an Object is a an actual instance of a Class. For example Employee ia a class, while John is a real employee which is an Object of Employee Class.
13.How polymorphism can be implemented ?
Some examples to implement polymorphism:
- Method Overriding
- Method Overloading
- Operator Overloading
14.What is Inheritance ?
In OOPs terminology, inheritance is a way to form new classes using classes that have already been defined. Inheritance is intended to help reuse existing code with little or no modification. The new classes, known as derived classes, inherit attributes and behavior of the pre-existing classes, which are referred to as base classes.
15.What is Method Overriding ?
- Method overriding allows a subclass to override a specific implementation of a method that is already provided by one of its super classes.
- A subclass can give its own definition of methods but need to have the same signature as the method in its super class. This means that when overriding a method the subclass’s method has to have the same name and parameter list as the super class’s overridden method.
16. What is Method Overloading ?
Method overloading is in a class have many methods having same name but different parameter called overloading or static polymorphism
17.What is Aggregation ?
Aggregation is a special form of association. Aggregation is the composition of an object out of a set of parts. For example, a car is an aggregation of engine, tyres, brakes, etc.
Aggregation represents a “Has” relationship like a car has a engine.
18.What is object oriented programming language ?
Object oriented programming language allows concepts such as abstraction, modularity, encapsulation, polymorphism and inheritance. Simula is the first object oriented language. Objects are said to be the most important part of object oriented language. Concept revolves around making simulation programs around an object.
19.What are the core ABAP oops concepts ?
- Inheritance: Inheritance is the ability of an object to inherit the properties and methods of another object. This characteristic leads to the creation of families of objects (just like families exist for humans) with parent objects and child objects.
- Polymorphism: Polymorphism is about an objects ability to provide context when methods or operators are called on the object.
20.Definition: Polymorphism
In object-oriented programming, polymorphism (from the Greek meaning “having multiple forms”) is the characteristic of being able to assign a different meaning to a particular symbol or “operator” in different contexts. The simple example is two classes that inherit from a common parent and implement the same virtual method.
21. Definition: Encapsulation
- Encapsulation: Encapsulation is the ability that an object has to contain and restrict the access to its members. Encapsulation is a key concept of object programming that ensures the autonomy and integrity of the objects.
- Abstraction: Another OOPS concept related to encapsulation that is less widely used but gaining ground is abstraction.
22.Definition: Abstraction
Through the process of abstraction, a programmer hides all but the relevant data about an object in order to reduce complexity and increase efficiency. In the same way that abstraction sometimes works in art, the object that remains is a representation of the original, with unwanted detail omitted. The resulting object itself can be referred to as an abstraction, meaning a named entity made up of selected attributes and behavior specific to a particular usage of the originating entity.
23.What is UML ?
- UML (Unified Modeling Language) is a standardized modeling language. It is used for the specification, construction, visualization and documentation of models for software systems and enables uniform communication between various users.
- UML does not describe the steps in the object-oriented development process.
- SAP uses UML as the company-wide standard for object-oriented modeling.
- UML describes a number of different diagram types in order to represent different views of a system.
24.What are the types of Objects and Classes ?
In general there are two types of Objects: Instance Object and Static Object and as such there are two types of Classes: Instance class and Static Class. Specifically when it comes to visibility, Private class, Protected class and Public classes are the types of classes one can have.
25.What are the types of classes which can be created ?
- We can create four types of classes under final and only modeled category(optional) with the private, protected, public and abstract instantiation.
- Usual Abap Class.
- Exception Class(With/Without messages).
- Persistent Class.
- Test Class(ABAP Unit).
26. What are the types of classes which can be created ?
- We can create four types of classes under final and only modeled category(optional) with the private, protected, public and abstract instantiation.
- Usual Abap Class.
- Exception Class(With/Without messages).
- Persistent Class.
- Test Class(ABAP Unit).
27.What is a reference variable ?
Objects can only be created and addressed using reference variables. Reference variables allow you to create and address objects. Reference variables can be defined in classes, allowing you to access objects from within a class.
28.What is a reference variable ?
Objects can only be created and addressed using reference variables. Reference variables allow you to create and address objects. Reference variables can be defined in classes, allowing you to access objects from within a class.
29.What is the difference between Abstract method and a Final method ?
- Abstract method
- Abstract instance methods are used to specify particular interfaces for subclasses, without having to immediately provide implementation for them. Abstract methods need to be redefined and thereby implemented in the subclass (here you also need to include the corresponding redefinition statement in the DEFINITION part of the subclass). Classes with at least one abstract method are themselves abstract. Static methods and constructors cannot be abstract (they cannot be redefined).
- Abstract (instance) methods are defined in the class, but not implemented
- They must be redefined in subclasses.
30.What is a super class ? How can it be implemented ?
A super class is a generalization of its subclasses. The subclass in turn is a specialization of its super classes.
31.What is a Narrowing Cast ? How can you implement it ?
The assignment of a subclass instance to a reference variable of the type “reference to superclass” is described as a narrowing cast, because you are switching from a more detailed view to a one with less detail.
32.What is a Widening Cast ?
The widening cast is, as with inheritance, the opposite of the narrowing cast: Here it is used to retrieve a class reference from an interface reference.
33.What is a singleton ?
If it is to be impossible to instantiate a class more than once (for example, because it serves as a data administrator or data container), you can use the singleton concept. The class is defined with the addition CREATE PRIVATE and FINAL and instantiated using its static constructor. A public static component could then make the reference to the class available to an external user.
34.What are the limitations of redefining a method ?
Inherited methods can be redefined in subclasses Redefined methods must be re-implemented in subclasses. The signature of redefined methods cannot be changed Static methods cannot be redefined. In inheritance, static components are “shared”: A class shares its non-private static attributes with all its subclasses. In ABAP Objects, you can not only add new components, but also provide inherited methods with new implementations. This is known as redefinition. You can only redefine (public and protected) instance methods, other components (static methods, attributes and so on) cannot be redefined. Changes to method parameters (signature changes) are not possible.
35.What are static components? What is a component selector ?
In inheritance, static components are “shared”: A class shares its non-private static attributes with all its subclasses. => and -> are the component selectors used to refer.
36.What are component instance ?
A component instance is a running component that can be run in parallel with other instances of the same component.
37.How is Encapsulation implemented in OOPs ?
Encapsulation means that the implementation of an object is hidden from other components in the system, so that they cannot make assumptions about the internal status of the object and therefore dependencies on specific implementations do not arise.
38.What are BADIs? What are BADI filters ?
BADI – Business Add Ins are enhancements to the standard version of the code of SAP.
Filter Badi- Business Add-Ins may be implemented on the basis of a filter value. If an enhancement for country-specific versions is provided for in the standard version, it is likely that different partners will want to implement this enhancement. The individual countries can create and activate their own implementation.
39.What are the types of Exception classes ?
- Global
- Local Exceptions Class.
40.Where can a protected method be accessed ?
Protected components Only visible within the class and its sub classes.
41.What is a signature of a method ?
- Methods have a parameter interface (called signature ) that enables them to receive values when they are called and pass values back to the calling program.
- In ABAP Objects, methods can have IMPORTING, EXPORTING, CHANGING, and RETURNING parameters as well as exception parameters.
- CLASS DEFINITION. … METHODS: [ IMPORTING TYPE EXPORTING TYPE CHANGING TYPE RETURNING VALUE() TYPE EXCEPTIONS RAISING ]. ENDCLASS.(signature of a method). CLASS IMPLEMENTATION. METHOD . … ENDMETHOD. ENDCLASS.
42.What is a functional Method ?
Methods that have a RETURNING parameter are described as functional methods. These methods cannot have EXPORTING or CHANGING parameters, but has many (or as few) IMPORTING parameters and exceptions as required.
43.What is a de-referenced variable ? What is a garbage collector ?
To go to an address before performing the operation a dereference variable is a pointer to the variable, not the variable itself. A pointer can be re-assigned any number of times while a reference cannot be reassigned after initialization. Field symbols are similar to dereference pointers. Thus, you can only access the content of the data object to which the field symbol points. (That is, field symbols use value semantics). If you want to access the content of the data object, you need to dereference the data reference first.
44.Can a class be defined without a constructor ?
Yes, class can be created without any constructor. Default constructor will be created when we define a class without constructor.
45.What Is The Difference In An Instance Method And A Static Method?
Instance method is available separately in each object (instance), static method is global and no instance is required for static method.
once .
46.What Is A Class In Ooabap?
Class is user defined data type which contains methods, events, attributes, interfaces etc.
47.What Is The Difference Between Singleton And Static Class In Sap Abap ?
Before going to static classes, you should understand static components.
- Static Components: Static components (static attributes, static events and static methods) exists globally, no need to create object/instance of the class to access them, we can access them by using static component selector => .
- Static Class: A class that only contains static components and no instance components is referred to as a static class.
- Singleton Class: It is a class which does not allow you to create multiple instances.
48.Can We Make Methods Of Interface As Abstract And Final In Ooabap ?
No we can not make interface methods as abstract or final in Object Oriented ABAP
49.Can We Declare Events In Interface In Ooabap ?
Yes, we can declare events in interface in Object Oriented ABAP
50.What Is A Singleton Class In Ooabap ?
Singleton class is a class which allows to instantiate(Create Object) only
51.What Is A Global Class In Sap ?
Global classes and interfaces are defined in the Class Builder (Transaction SE24) in the ABAP Workbench.All of the ABAP programs in an R/3 System can access the global classes
52.What Is A Local Class In Sap ?
Local classes are defined in an ABAP program (Transaction SE38) and can only be used in the program in which they are defined.
53.What Is An Event In Ooabap ?
Event is a mechanism by which method of one class can raise method of another class, without the hazard of instantiating that class.
54.How To Declare And Raise Events In Ooabap ?
We need to follow below steps when working with events in Object Oriented ABAP:
- Define an event
- Define a method
- Link event and method and convert the method into event-handler method
- Create a triggering method which will raise the event
- Use set handler and register event handler method to a particular instance in the program
55.What Is A Constructor Method In Ooabap ?
- These are special type of methods
- constructor method is executed automatically whenever a object is created or instantiated
- These methods are mainly used to set default values in a class
- The name of the constructor method is ‘constructor’
- These methods have only importing parameters
- There are no exporting parameters
56.What Is Abstract Method In Ooabap ?
Abstract methods is a method which doesn’t contain any implementation.
57.What Is An Abstract Class In Ooabap ?
- It is a class which contains methods with implementation as well as methods without implementation .
- Abstract class is a class which contains at least one abstract method.
58.Can We Instantiate Abstract Class In Ooabap ?
- we cannot create an object to the abstract class instead create an object to the child class and call the methods .
- Abstract class are mainly used for creating inheritance.
59.What Is The Use Of ‘defination Deferred’ Keyword In Ooabap ?
It is the keyword which indicates the class definition is delayed or postponed or Defined at some place in program.
Syntax : CLASSÂ Â DEFINITION DEFERED.
60.What Are The Advantages Of Oo Alv ?
Some of the main advantages of Object Oriented ALV
- We have no of events available in the classes when compared to ALV with function modules which gives flexibility for the programmer to develop ALV’S for various scenarios.
- We can display more than one ALV grid data on a single screen.
- The ALV grid data is displayed in the form of custom container with which we can control the size of ALV grid Whereas we cannot control the size of the ALV with function Modules.
- We can also place different UI elements like checkbox, Radiobutton on the same screen in addition ALV grid data.
61.What Are The Types Of Constructor’s In Ooabap ? Explain ?
CONSTRUCTOR’s are special type of methods, constructor method is executed automatically whenever a object is created or instantiated.
- Constructor: This method is executed automatically whenever object is created, this is used to set default values with respect to instance/object. The name of the constructor method is CONSTRUCTOR.
- Static Constructor: This method is executed automatically whenever object is created, this is used to set default values globally irrespective of instances/objects.The name of the static constructor is CLASS_ CONSTRUCTOR.
62.What Is A Polymorphism In Ooabap ?
Polymorphism is a concept by which the same method names will behave differently in different classes i.e each method will have it’s own implementation in different classes but with the same name.
63.Can We Defined A Class Without A Constructor In Ooabap ?
Yes, class can be created without any constructor. Default constructor will be created when we define a class without constructor.
64.What Is A Friend Class?
Friend class is a class it can access private components of it’s friends class.
65.What Is Alias?
Instead of specifying full name of interface methods, we can assign it a name which can directly trigger.
66.What Is Me Variable?
It just like a selfreference, by this we can call methods that are with in same class with out creating object.
67.How To A Create Object For The Class?
Data: ref type ref to .
Create object ref.
68.How To Call A Method?
Call method ref>method_name .
69.What Are The Differences Local & Global Classes?
- Local classes are defined locally with in a program and the other programs can’t access the same classes directly.
- But global classes are not like that they are globally accessible from ABAP environment.
- Global classes are centrally defined in a repository. Transaction code for global classes is SE24(class builder).
70.What Is The Difference Between Function Group And Classes?
We can create many instances of the same class with in a program, but we cannot create many instances of function group.
71.How Many Types Of Classes Are There In Ooabap?
- Public class
- Private class
- Final class
- Singleton class
- Abstract class
- Persistent class
- Friend class
72.How To Define A Class Locally?
class <cl_name> definition.
Public section.
Methods: m1 importing p1 type
Exporting p2 type
Changing p3 type
Returning p4 type
Exceptions
Protected section
Private section
Endclass
Class <c1_name> implementation.
Method m1.
Endmethod.
Endclass
73.How To Create An Object For Private Class?
In general we can not create object for a private class, but we can access static method of a private class so call that method using its class name and import that object.
For example take one static method with an exporting parameter inside private class and write object creation code in that static method and export that object.