1. What Is OOPS ABAP?
Answer: 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. What are the core ABAP oops concepts?
Answer: 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.
3. What is a reference variable?
Answer: 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.
4. 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.
5. What Is A Singleton Class In Ooabap?
Answer: Singleton class is a class which allows instantiating (Create Object) only.
6. What Are The Advantages Of Oo Alv?
Answer: Some of the main advantages of Object Oriented ALV
- We have no events available in the classes when compared to ALV with function modules which give 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 a custom container with which we can control the size of the 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 to ALV grid data.
7. What Are The Differences Local & Global Classes?Answer: Local classes are defined locally within 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 the ABAP environment. Global classes are centrally defined in a repository. Transaction code for global classes is SE24(class builder).
8. Can We Instantiate Abstract Class In Ooabap?
Answer: we cannot create an object to the abstract class instead create an object to the child class and call the methods.
An abstract class is mainly used for creating inheritance.
9. What Is A Class In Ooabap?
Answer: Class is a user-defined data type which contains methods, events, attributes, interfaces, etc.
10. What Is The Difference Between Abstract Class And Interface?
Answer: 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 an instance for the abstract class is mainly for inheritance.
The interface contains methods without implementation.
11. Is It Mandatory To Implement All Methods Of Interface In The Class Which Includes Interface?
Answer: No it is not mandatory to implement all normal interface methods but it is mandatory to implement all Abstract methods.
12. What Is An Abstract Class In Ooabap?
Answer: It is a class which contains methods with implementation as well as methods without implementation.
An abstract class is a class which contains at least one abstract method.
13. What Is A Polymorphism In Ooabap?
Answer: Polymorphism is a concept by which the same method names will behave differently in different classes i.e each method will have its own implementation in different classes but with the same name.
14. What Is The Difference Between Function Group And Classes?
Answer: We can create many instances of the same class within a program, but we cannot create many instances of function group.
15. WHAT IS AN INTERFACE IN OOABAP?
Answer: The interface is class which contains methods without implementations.
16. What Are The Types Of Constructors In Ooabap? Explain?
Answer: CONSTRUCTOR’s are a special type of methods, the constructor method is executed automatically whenever an object is created or instantiated.
- Constructor: This method is executed automatically whenever an 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 an object is created, this is used to set default values globally irrespective of instances/objects. The name of the static constructor is CLASS_ CONSTRUCTOR.
17. What is Encapsulation in Object-Oriented Programming(OOP)?
Answer: Encapsulation is the main concept in OOP. Encapsulation means hiding attributes and methods from the outside world, so in this way, we can restrict the visibility of an object( an instance of a class) components(attributes and methods).
18. What is Inheritance in OO ABAP?
Answer: Deriving a new class from an existing class is called Inheritance. The existing class is called as Superclass and derived new class is called as Subclass. Derived class get all attributes and methods from the superclass and in addition to that, we create new attributes and methods.
19. What is Narrow Casting?
Answer: Definition: 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. 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(superclass) class. However, in order to allow the user to work with cars, buses, 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 subclass is assigned to the reference of type superclass.
2. Using the superclass reference it is possible to access the methods from the object which are only defined at the superclass.
3. This access is also called as generic access as superclass is normally called a general class.
20. What are an abstraction, encapsulation, and polymorphism?
Answer: 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 the 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.
21. What Is Alias Name In Ooabap? Answer: Alias is an alias name for the interface method implemented in the class.
22. How do you achieve encapsulation in OO ABAP?
Answer: We can achieve encapsulation in OO ABAP by using PUBLIC, PRIVATE and PROTECTED keywords in OO ABAP. These are also called as access specifiers.
23. What is the Event Handler Technique in Object-oriented ABAP?
Answer: 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 the 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 the same/other class.
- Register the event handler method in the program.
Now, the above settings are complete for an event handler in class. Create an object from the class containing the event and call the triggering method to raise the event.
24. What is Method Overriding?
Answer: Method overriding allows a subclass to override a specific implementation of a method that is already provided by one of its superclasses.
A subclass can give its own definition of methods but need to have the same signature as the method in its superclass. This means that when overriding a method the subclass’s method has to have the same name and parameter list like the super class’s overridden method.
25. What is UML?
Answer: 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.
26. How polymorphism can be implemented?
Answer: Some examples to implement polymorphism:
- Method Overriding
- Method Overloading
- Operator Overloading
27. What Is The Difference In Attributes Defined In The Public Versus Private Section Of A Class? Answer: Public attributes can be accessed by class, subclasses and other classes whereas Private attributes can be accessed by the class itself only.
28. What are Abstract Classes and Methods in Object-Oriented Programming?
Answer: Abstract Class: Classes which contain one or more abstract methods or abstract properties, such methods or properties do not provide the implementation. These abstract methods or properties are implemented in the derived classes (Sub-classes).
Abstract classes do 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 (Subclasses).
29. What is the Visibility of Component?
Answer: Each class component has 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.
30. What is the difference between Class and Object?
Answer: A-Class is actually a blueprint or a template to create an Object. Whereas an object is an actual instance of a Class. For example Employee in a class, while John is a real employee which is an Object of Employee Class.
31. What is Inheritance?
Answer: 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.
32. What is object-oriented programming language?
Answer: 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 an object-oriented language. The concept revolves around making simulation programs around an object.
33. What are the types of Objects and Classes?
Answer: 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.
34. What is the difference between Abstract method and a Final method?
Answer: Abstract method
Abstract instance methods are used to specify particular interfaces for subclasses, without having to immediately provide an 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.
35. How is Encapsulation implemented in OOPs?
Answer: 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.
36. What Is An Event In Ooabap?
Answer: Event is a mechanism by which method of one class can raise method of another class, without the hazard of instantiating that class.
37. What Is A Constructor Method In Ooabap?
- These are a special type of methods constructor method is executed automatically whenever an 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.
38. Can We Defined A Class Without A Constructor In Ooabap
Answer: Yes, the class can be created without any constructor. The default constructor will be created when we define a class without a constructor.
39. How To Create An Object For Private Class?
Answer: In general, we can not create an object for a private class, but we can access the 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 the private class and write the object creation code in that static method and export that object.
40. What Is The Difference Between Singleton And Static Class In Sap Abap?
Answer: 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.
41. What is a de-referenced variable? What is a garbage collector?
Answer: 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.
42. How Many Types Of Classes Are There In Ooabap?
- Public class
- Private class
- Final class
- Singleton class
- Abstract class
- Persistent class
- Friend class.
43. What are the different components available in Clas?
Attributes, Methods, Events, Types, and Constants are different components which are available in Class
44. What are the principles of Object-Oriented Programming(OOP)?
Answer: There are 4 major principles in OO Programming. They are of Abstraction, Encapsulation, Inheritance, and Polymorphism.
45. What are the Instance and Static Components?
Answer: 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 exist globally for a class and are referred to using a static component selector.
46. What is a Narrowing Cast? How can you implement it?
Answer: 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.
47. What is Method Overloading?
Answer: Method overloading is in a class have many methods having the same name but different parameter called overloading or static polymorphism.
48. What is FRIENDS keyword?
Answer: In any Object Oriented programming language, access to private or protected components – both methods and attributes – would be prohibited. If someone tries to access them, the compiler would generate a syntax error.
Sometimes, it would be advantageous to give access to these protected and private attributes to other classes. This can be achieved using FRIENDS addition.
49. How To Declare And Raise Events In Ooabap?
Answer: We need to follow the 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 the event – handler method
- Create a triggering method which will raise the event Use set
- handler and register the event handler method to a particular instance in the program
50. What is the Use of final class?
Answer: Final Classes and Methods in Object-Oriented Programming
Final Class: A class that is defined as a 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.