[go: up one dir, main page]

0% found this document useful (0 votes)
2 views6 pages

FAQs_OOPs

Download as txt, pdf, or txt
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 6

OOP's ABAP:

------------
OOPS Function Module
It is object-oriented. It is procedural oriented.
It uses objects and classes. It contains a block of code for a specific
functionality
It is a bottom-up approach. It is a top-down approach.
Inheritance is possible. Inheritance is not possible.
Polymorphism is possible. Polymorphism is not possible.
Have access specifiers:
Private, public, and Protected. Does not have any access specifier.

1. How do you define OOP's ABAP?


- It works based on following concepts.
Data Abstraction - A class with methods, events, interface and attributes.
Data Encaptulation - Securing from outside world, in other words methods or
attributes of a class can be accessed using class object or class by the visibility
(PUBLIC/PROTECTED/PRIVATE) of the methods or attributes.
Polymorphism - Behaves differently in different cases, Ex. BADI.
-polymorphism is that we don�t need to define a method for different
scenarios of implementation.
Same definition can be used for different implementations.
Inheritance - Aquiring one class (Super Class) functionality to another class (Sub-
Class).

2. Types of classes?
- ABAP class, Abstract Class, Exception Class, Persistent Class, Final.

ABAP Class- SE24

EXCEPTION CLASS - A class to handle the exceptions occurred during runtime or


program execution.
CLASS we use mostly -CX_ROOT.
Persistent Class- A data is said to be persistent if it can be preserved beyond the
runtime of program.

Abstract class?
- Abstract Class is a special kind of class which can�t be instantiated.
Abstract class should at least contain one abstract method.
Abstract methods are declared without any implementation.
These abstract methods are implemented in the derived classes (Sub-classes).

Class with at least one abstract method (which does have implementation) is
known as �Abstract class�.
Example: Let�s take a simple real time scenario, where �TELEPHONE� is your
class. This class is having four Methods (each method depicts one functionality):

1)PICKUP_CALL
2)DROP_CALL
3)REJECT_CALL
4)DIAL_NUMBER(the functionality of this method is same, that is dialing a
number. But the implementation could be different in different scenarios.)

--FINAL class?
- If a class is defined as FINAL class then there won't be any sub-class for that
class, in other words inheritance will not be possible for that class.

3. What Is An Interface In Ooabap?


- Interface is like a class which contains methods declaration without methods
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, we can have multiple inheritance of interfaces.

6. Does Polymorphism Achieved Through Interfaces?


Yes, BADI interfaces work based on polymorphism concept.

7. What is the Difference between Class and Object ?


- A Class is actually a blueprint or a template with the required elements
(Attributes, Events, Methods, Interfaces, etc).
Whereas an Object is a an actual instance of a Class.
For example Employee is a class/template, while the name John is a real employee
which is an Object of Employee Class.

8. What Is Alias Name In Ooabap?


- Alias is an alternative 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 define events in interfaces.
Interface methods are fixed but can be used for different functionalities in
different cases (We call it as polymorphism - BADI is the example).
Whereas class is having common behaviour in all the cases becuase logic inside
the method is fixed.

10. What is Inheritance ?


- Inheritance is creating new class referring to another class that have already
been defined.
Inheritance is to reuse existing code with modification or no modification.
The new class is known as derived class or child class or sub-class and the
referred class is known as base class or parent class or super class.

11. What are the types of Objects and Classes ?


- There are two types of Objects: Instance Object and Static Object.
There are two types of Classes: Instance class and Static Class.

12. How to differentiate instance & static components?


Local Class:
- If we declare using CLASS-DATA or CLASS-METHODS then we call them as static, if
we declare using DATA, METHODS then they are instance.
Global Class:
- Every element should be specified either instance or static in component type
section.
Static attributes/methods can be accessed via object or directly with class name
(object is required for instance case).
Static attributes/methods can be accessed using => (Double implise) but instace
can be accessed using -> (Single implise).

13. Where can a protected method be accessed ?


- Protected components Only visible within the class and it's sub classes only.

14. What is a signature of a method ?


- Methods have parameters (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.

15. Can a class be defined without a constructor ?


- Yes, class can be created without constructor method but constructor will be
called by default when we create an object.

16. What Is The Difference In An Instance Method And A Static Method?


- Instance method is available for each object as fresh (instance),
- static method is global and instanciation is optional and the logic remains same
through out class.

17. What Is The Use Of �defination Deferred� Keyword In Ooabap ?


- It is the keyword which indicates the class definition can be done after the
object creation.
- In other words declaring object reference 1st and class can be defined later,
generally we define class first then declare the object referring to class.

18. What Is A Friend Class?

- Friend class is a class it can access private components of super class.

19. What Is ME Variable?


- It just like a self�reference, by this we can call methods that are with in same
class without creating object.

20. What is abstract class?


- Abstract Class is a special kind of class which can�t be instantiated.
Abstract class should at least contain one abstract method.
Abstract methods are declared without any implementation.
These abstract methods are implemented in the derived classes (Sub-classes).

Class with at least one abstract method (which does have implementation) is
known as �Abstract class�.
Example: Let�s take a simple real time scenario, where �TELEPHONE� is your
class. This class is having four Methods (each method depicts one functionality):

1)PICKUP_CALL
2)DROP_CALL
3)REJECT_CALL
4)DIAL_NUMBER(the functionality of this method is same, that is dialing a
number. But the implementation could be different in different scenarios.)

21. Explain the steps to display ALV using OOPs?


- a. Create a screen.
b. Place custom control in the screen.
c. Create a container for the control using CL_GUI_CUSTOM_CONTAINER class.
d. Create a grid for the container using CL_GUI_ALV_GRID class.
e. Fill the field catalog & final internal table.
f. Call SET_TABLE_FOR_FIRST_DISPLAY method (by exporting data table and field
catalog table) of class CL_GUI_ALV_GRID to display data in ALV.

22. How do you handle events in OOPs ALV?


- Define & Implement a local class with the required methods respective to each
event of CL_GUI_ALV_GRID.
Use SET HANDLER keyword to register the events and call the respective event
method.

23. Can we create a OOPs ALV without using custom container?


- Yes, we can create using CL_SALV_TABLE class with FACTORY, DISPLAY methods.
We can't prepare the fieldcatalog in SALV, so we might miss edit, color, hotspot
etc functionalities.

24. How do you handle exceptions in OOPs?


- Using RAISE EXCEPTION or Using TRY, CATCH & ENDTRY concept.
catch� a program uses an exception handler to catch an exception.
It is added to the section of a program where you need to handle the
problem. It�s done using the catch keyword.
try� The try block identifies the code block for which certain exceptions will be
activated.
It should be followed by one/more catch blocks.

25. Can you tell me few exception classes you used?


- There are many exception classes provided by SAP but I always use CX_ROOT because
it will support for any type of exceptions.

26. What is constructor?


- It's a default method that will be called whenever we create an object.
Whenever we create a class in SE24 there we can find constructor button in
application toolbar, by clicking on it constructor method will be generated.
If we want we can add the import & export parameters to constructor method.

27. Wht is singleton class?


- It will have only one instance (object).
We need to declare the constructor method as private.
The advantage of using a private constructor in Singleton class (No one can
create an object of your class),
in other words the class elements can be accessed only within the class.

A class is said to be a singleton class if it can have the utmost one


instance only.

Following is a procedure to create a singleton class :

1)Visibility of class should be private.


2)Declare a private attribute with reference to the same class, in
which it is being declared.
3)Create a public static method with returning parameter, having a
reference of the same class.
4)Create an implementation and an object inside the implementation of
a public static method.
5)To create an instance for the singleton class, call this public
static method in any program.

28. What are the types of CONSTRUCTOR's in OOABAP ?


- Constructor method is the default method will be called whenever we create an
object.
Instance Constructor: Create using CONSTRUCTOR keyword.
Static Constructor: Create using CLASS-CONSTRUCTOR keyword.

29. What is Persistence class?


- Persistence class stores the object permanently in database, It performs
serialization technique.
That means if any transaction fails inbetween the proces then we can get back old
transaction & we can continue further.
Ex. When we are booking a ticket online and while doing payment if our
transaction fails that seat which we selected will be blocked for some time
and the information stored in persistant layer (RAM).
30. Explain about Encaptulation or Visibility in OOPS?
- PUBLIC - All can access the class elements (Attributes, Methods, Events).
PROTECTED - Only Super Class & it's sub-class only can access it's elements.
PRIVATE - Only Super class & it's Friend class only can access it's elements.

31. What is NARROW or UP casting & WIDE or DOWN casting process?


- Assigning/copying the instance (object) of sub class to super class instance is
called Narrowing Cast or UP Casting.
Assigning/coping the instance (object) of super class to the sub class instance
is called as Widening Cast.
*** Make sure source & target instances should have same type otherwise the
Widening cast will always fail.
When we use Widening casting then we use type casting operator ?= but we can
use = for Narrowing casting.

32. What is REDEFINITION?


- In some cases we need to create sub-class by referring to super class.
In such cases we can use the same method name but logic to be replaced then we
use REDEFINITION keyword.

33. How many INHERITANCE can be possible to a class?


- OO ABAP supports single inheritance only on the class.
Each super class can have multiple sub-classes but each sub-class will have only
one super class.
Multiple inheritance possible with interface but not with class.

34. What is FINAL class?


- If a class is defined as FINAL class then there won't be any sub-class for that
class, in other words inheritance will not be possible for that class.

35. 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.
We call it as method REDEFINITION.

36. What is Method Overloading ?


- A class have many methods having same name but different parameters called
overloading.
OOP's ABAP does not support method overloading

37. What are the limitations of redefining a method ?


- Methods can be redefined in subclasses,
Redefined methods must be re-implemented in subclasses.
The signature of redefined methods cannot be changed.
Static methods & Private methods cannot be redefined.

38. What Are The Advantages Of OOP's Alv ?


- Events in OOP's ALV are more than ALV FM.
We can display more than one ALV grid data on a single screen (by creating
multple custom containers in that screen).

39. What Is The Difference Between Function Group And Classes?


- We can create N number of methods in the class, but max 99 FMs only allowed per
function group.
If we call a method out of multple methods only that method will be loaded in
ABAP program
but all the FMs associated to the function group will be loaded in core ABAP.

40. What is the difference between abstract class & interface?


Interface Abstract Class
-----------------------------------------------------------------------------------
-------------------------------------------------
1. It is not a class. 1. It is a special class
which can't be instantiated.
It is an independent structure that is used
in a class to extend the functionality of a class.
2. Methods are declared but no implementation. 2. It can contain methods
with implementation as well as without implementation.
3. No common behaviour. 3. For non-abstract methods common
behaviour can be implemented.
4. All components are PUBLIC by default. 4. The visibility of each component
can be set.
5.It can inherit multiple interfaces but cannot 5. It can inherit a class
and multiple interfaces.
inherit a class.
6.Multiple inheritance can be achieved. 6. There is only one
abstract class as Super Class.

You might also like