Object Oriented Programming Language Interview Questions and Answers for freshers pdfFull description
Full description
Full description
SAP ABAP
Q7AFull description
SAP SD interview questions
interview
SAP SD interview questionsFull description
oops abapFull description
SAP Web Dynpro ABAP Interview Questions With AnswersFull description
ABAP Interview questions
Full description
Mysql Interview Questions and AnswersFull description
ODI
Full description
LTE Interview Questions and AnswersDescription complète
http://sapababinterviewquestions.blogspot.in/p/sap-oops-interview-questions.html SAP ABAP OOPS Interview Questions and Answers 1. Difference between Local Class and Global Class ?
Local and Global Classes Classes in ABAP Objects can be declared either globally or locally. You define global classes and interfaces in the Class Builder (Transaction SE24) in the ABAP Workbench. They are stored centrally in class pools in the class library in the R/3 Repository. All of the ABAP programs in an R/3 System can access the global classes. Local classes are defined within an ABAP program. Local classes and interfaces can only be used in the program in which they are defined. When you use a class in an ABAP program, the system first searches for a local class with the specified name. If it does not find one, it then looks for a global class. Apart from the visibility question, there is no difference between using a global class and using a local class. There is, however, a significant difference in the way that local and global classes are designed. If you are defining a local class that is only used in a single program, it is usually sufficient to define the outwardly visible components so that it fits into that program. Global classes, on the other hand, must be able to be used anywhere. This means that certain restrictions apply when you define the interface of a global class, since the system must be able to guarantee that any program using an object of a global class can recognize the data type of each interface parameter. 2. What is Final Class ? If u do not want that, anyone change or override the functionality of that class, you can declare it as final. A final class cannot be redefined further. Lastly if only a method of class is final, then that class can be inherited but that method cannot be re defined. http://wiki.sdn.sap.com/wiki/display/ABAP/ABAP+Objects++Inheritance+in+ABSTRACT+and+FINAL+Local+Classes+-+Example 3. What is Friend Class? When we use Friend Class? There are certain special cases where a class would want access to other classes private attributes and methods in such scenario we can make use of the friends concept in classes. If a class A declares itself as a friend to class B then class B will have access to all the private and protected attributes and methods of class A. *&---------------------------------------------------------------------* *& Report YCL_FRIENDS *& *&---------------------------------------------------------------------*
REPORT ycl_friends.
CLASS abc_employs DEFINITION DEFERRED. *----------------------------------------------------------------------* * CLASS abc_org DEFINITION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS abc_org DEFINITION FRIENDS abc_employs. PUBLIC SECTION. DATA : stock_price TYPE char10 VALUE 100. METHODS display_stock_price. PRIVATE SECTION. DATA : avg_ctc TYPE char10 VALUE 200. METHODS display_avg_ctc. ENDCLASS.
"abc_org DEFINITION
*----------------------------------------------------------------------* * CLASS abc_org IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS abc_org IMPLEMENTATION. METHOD display_stock_price. WRITE / stock_price. SKIP. ENDMETHOD.
*----------------------------------------------------------------------* * CLASS abc_employs DEFINITION *----------------------------------------------------------------------* *
*----------------------------------------------------------------------* CLASS abc_employs DEFINITION INHERITING FROM abc_org. PUBLIC SECTION. METHODS : display_emp. ENDCLASS.
"abc_employs DEFINITION
*----------------------------------------------------------------------* * CLASS abc_employs IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS abc_employs IMPLEMENTATION. METHOD display_emp. DATA ref_empl TYPE REF TO abc_org. CREATE OBJECT ref_empl. CALL METHOD ref_empl->display_stock_price. CALL METHOD ref_empl->display_avg_ctc. ENDMETHOD. ENDCLASS.
"display_emp "abc_employs IMPLEMENTATION
*----------------------------------------------------------------------* * CLASS abc_shareholder DEFINITION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS abc_shareholder DEFINITION INHERITING FROM abc_org. PUBLIC SECTION. METHODS display_shr.
ENDCLASS.
"abc_shareholder DEFINITION
*----------------------------------------------------------------------* * CLASS abc_shareholder IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS abc_shareholder IMPLEMENTATION. METHOD display_shr. DATA ref_shr TYPE REF TO abc_org. CREATE OBJECT ref_shr. CALL METHOD ref_shr->display_stock_price. CALL METHOD ref_shr->display_avg_ctc. " This will throw an error.
*
ENDMETHOD. ENDCLASS.
"display_emp "abc_shareholder IMPLEMENTATION
START-OF-SELECTION. DATA : ref_emp TYPE REF TO abc_employs, ref_shr TYPE REF TO abc_shareholder. CREATE OBJECT ref_emp. CREATE OBJECT ref_shr. CALL METHOD ref_emp->display_emp. CALL METHOD ref_shr->display_shr.
4. What is the use of Abstract Class ? Abstract Class is a special kind of class which can’t be instantiated. We can only instantiate the subclasses of the Abstract class if they are not abstract. Abstract class should at least contain one abstract method. Abstract methods are methods without any implementation – only a declaration. We can certainly define the variables referencing to Abstract class and instantiate with specific subclass at runtime.
-> We can define some common functionalities in Abstract class (Super-class) and those can be
used in derived classes (Sub classes).
REPORT ze00707_abstract. *----------------------------------------------------------------------* * CLASS lcl_abstract DEFINITION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS lcl_abstract DEFINITION ABSTRACT. PUBLIC SECTION. METHODS : abstract_display ABSTRACT. METHODS : display. ENDCLASS. "lcl_abstract DEFINITION *----------------------------------------------------------------------* * CLASS lcl_abstract IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS lcl_abstract IMPLEMENTATION. METHOD display. WRITE:/ 'Normal method'. ENDMETHOD. "display
ENDCLASS. "lcl_abstract IMPLEMENTATION *----------------------------------------------------------------------* * CLASS lcl_class DEFINITION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS lcl_class DEFINITION INHERITING FROM lcl_abstract. PUBLIC SECTION. METHODS abstract_display REDEFINITION. METHODS class_display. ENDCLASS. "lcl_class DEFINITION Abstract Class Object Oriented concepts in ABAP *----------------------------------------------------------------------* * CLASS lcl_class IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS lcl_class IMPLEMENTATION. METHOD abstract_display. WRITE:/ 'Abstract method'. ENDMETHOD. "abstract_display METHOD class_display.
START-OF-SELECTION. DATA : l_ref TYPE REF TO lcl_class. CREATE OBJECT l_ref. l_ref->class_display( ). l_ref->abstract_display( ). l_ref->display( ).
5. What is the use of an Interface ? The Main Difference Between the Abstract Class And the Interface are: 1) When inheriting A Interface We have to inherit all the methods of the Interface there's no other option whereas with abstract classes we can inherit the members that we are in need of. 2) The Main difference between these is that Interface cannot have any declaration within it. Just the interface has to have body of the method and the method is to be used by the classes inheriting it. Whereas in the case of Abstract Class it can have declarations (Other than the abstract method) and it can be further extended in the classes inheriting the Abstract Class.