Saturday, February 2, 2013

SAP-ABAP-Interface-Abstract-Class-Interview-Questions-Answers

SAP-ABAP Interface, Abstract Class Interview Questions Answers, this post consist of commonly asked interview questions on Interfaces and Abstract Classes in OOABAP and difference between Interface and Abstract Class. Refer this post to more about Interface and Abstract Classes in SAP ABAP, and also for Interview Questions on Interfaces & Abstract Class. Click on read more refer this post.



SAP-ABAP-Interface-Abstract-Class-Interview-Questions-Answers


SAP-ABAP Interface, Abstract Class Interview Questions Answers, this post consist of commonly asked interview questions on Interfaces and Abstract Classes in OOABAP and difference between Interface and Abstract Class. Refer this post to more about Interface and Abstract Classes in SAP ABAP, and also for Interview Questions on Interfaces & Abstract Class.




1) What is an Interface?

Ans) 

Interfaces are independent structures that you can implement in a class to extend the scope of that class. Interfaces, like classes, define a set of properties, methods, and events. 

But unlike classes, interface methods do not provide implementation. They are implemented by classes, and defined as separate entities from classes.



2) Can we instantiate the interface?

Ans) No, we cannot instantiate an interface.



3) Can we achieve multiple inheritance using Interfaces?

Ans) 

Yes, multiple inheritance concept can be achieved using interfaces. Different interfaces can be implemented in single class.



4) Can we assign values to attributes of interface inside interface?

Ans) 

We cannot assign values to attributes of the interface except for constants. To assign values to interface attributes we need to use DATA VALUES option in the class while implementing interface.


Example:-

interface inf1.
data w_i type i.
constants w_c type i value 435.
endinterface.



Class zlcl_a definition.
public section.
INTERFACES inf1 data values w_i = 45.
endclass.



5) Does polymorphism achieved through interfaces?

Ans) 

Yes, we can achieve polymorphism using interfaces. Interfaces, along with inheritance, provide one of the pillars of polymorphism, since they allow a single method within an interface to behave differently in different classes.



6) Where can an interface be implemented in the class?

Ans) Interfaces can only be implemented in public section of the class.



7) Is it mandatory to implement all methods of interface in the class which includes interface?

Ans) Yes, all the methods of the interface need to implemented in the class.



8) What is the difference between abstract class and interface?


Ans)


                     INTERFACE

                ABSTRACT CLASS

1) Interfaces cannot be instantiated.
1) Abstract class also cannot  be instantiated
2) Interfaces cannot have implementation.
2) Abstract class can have implementation.
3) All the methods of the interface need to be implemented in the class.
3) Only abstract methods need to be implemented in the subclass.

4) No need to use Redefinition key word while implementing inheritance method in the class.

4) Need to use Redefinition key word while implementing inheritance method in the class.



9) What is alias?

Ans) 

Aliases are the names for the interface components with which we cal call the interface methods in order to avoid ambiguity. The method can directly called using alias names.
Syntax to declare alias name:


ALIASES <alias> FOR intf~comp.



10) Can we make methods of interface as abstract and final?

Ans) 

Yes, we can make methods of interface as abstract and final using following options.


Syntax:-

INTERFACES intf 

            { {[ABSTRACT METHODS meth1 meth2 ... ] 

            [FINAL METHODS meth1 meth2 ... ]} 

            | [ALL METHODS {ABSTRACT|FINAL}] }



Note: - 

To make interface methods as abstract methods first we need to make the class which implements interface as abstract class.



11) Can we do upcast and downcast using interface references?

Ans) Yes, we can perform casting on interface references.


Suppose we have a class reference <cref> and interface references <iref>, <iref1>, and <iref2>. The following assignments with interface references can be checked statically:

  • <iref1> = <iref2>

Both interface references must refer to the same interface, or the interface of <iref1> must contain the interface <iref2> as a component.

  • <iref> = <cref>

The class of the class reference <cref> must implement the interface of the interface reference <iref>.


  • <cref> = <iref>

The class of <cref> must be the predefined empty class OBJECT.


In all other cases, you would have to work with the statement MOVE ...? TO or the casting operator (?=). 

The casting operator replaces the assignment operator (=). In the MOVE... ? TO statement, or when you use the casting operator, there is no static type check. 


Instead, the system checks at runtime whether the object reference in the source variable points to an object to which the object reference in the target variable can also point. 


If the assignment is possible, the system makes it, otherwise, the cacheable runtime error MOVE_CAST_ERROR occurs.


You must always use casting for assigning an interface reference to a class reference if <cref> does not refer to the predefined empty class OBJECT:


<cref> ?= <iref>



For the casting to be successful, the object to which <iref> points must be an object of the same class as the type of the class variable <cref>.


12) Can we declare events in interface? 

Ans) Yes.


13) Can we raise events in interface? 

Ans) No.




Dear ABAPers if you know any interview questions related this Interface & Abstract Class topic please share on below comment box.

"You found the information helpful and want to say thanks? Your donation is enough to inspire us to do more. Thanks a bunch!"

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Categories

ABAP (1) ABAP Interview Questions (112) ABAP Open SQL Statements (1) ABAP Syntax Rules (6) ABAP WORKBENCH (2) ABAP-Interview-Questions (52) ALE IDOC (6) ALE IDOC Interview Questions (6) ale-idoc (6) ALE-IDOC-Interview-Questions (19) ALV Interview Questions (5) ALV-Interview-Questions (22) BADI (2) BAPI (1) BAPI Interview Questions (1) BAPI-Interview-Questions (14) BDC (6) BDC Interview Questions (6) BDC-Interview-Questions (9) big data (2) big data interview questions (1) Classical Reports Interview Question (3) Classical-Reports-Interview-Questions (22) Conditional Statements (1) Cross Applications (3) Cross-Applications (14) Data Dictionary (22) Data Type Questins (1) Data types (1) Data-Dictionary (48) Data-Type-Questins (6) Dialog programming (5) Dialog Programming Interview Questions (4) Dialog-Programming (30) DOMAIN Interview Questions (1) Domain-Interview-Questions (8) Function Module (2) hadoop (2) hadoop interview questions (2) hdfs (1) IDoc Tutorials (6) Interactive Report Interview Questions (4) Interactive-Reports-Interview-Questions (22) Internal Tables (1) interview questions (1) Lock Object Interview Questions (1) Lock-Objects-Interview-Questions (10) Logical Database (1) Modularization Interview Questions (4) Modularization-Interview-Questions (25) Module Pool Programming (5) Module-Pool-Programming (39) modules in sap (1) Object Oriented ABAP (19) Object Oriented ABAP Interview Questions (15) object-oriented-abap (2) Object-Oriented-ABAP-Interview-Questions (34) OOABAP (9) Reports (14) Reports Interview Questions (9) Reports-Interview-Questions (19) RFC (1) RFC Interview Questions (1) RFC-Interview-Questions (14) RICEF (1) RICEF Objects (1) SAP (4) SAP ABAP (4) SAP ABAP Interview Questions (42) SAP ABAP Introduction (46) SAP ABAP Message Types (2) SAP BADI Interview Questions (2) SAP Basics (71) SAP Books (2) SAP Certification (1) SAP CONSULTANTS (5) SAP CRM (1) SAP ENHANCEMENTS (3) SAP EXITS (2) SAP EXITS ( SAP ENHANCEMENTS ) Interview Questions (1) SAP Free Books (1) SAP HR (2) SAP Lock Object (1) sap modules (2) SAP Open SQL Statements (1) SAP R/3 Architecture (4) SAP Search help (1) SAP Smartforms (1) SAP Smartforms Interview Questions (2) SAP Tables (5) SAP Tcodes (10) SAP Views (1) SAP Webdynpro ABAP (12) SAP Work Processors (2) SAP Workflow (3) SAP-BADI-Interview-Questions (11) SAP-Enhancements (39) SAP-Exits (39) SAP-Exits-Enhancements-Interview Questions (3) SAP-HANA (1) SAP-HANA-Interview-Questions (1) SAP-Smartforms-Interview-Questions (2) SAP-Workflow (3) Scripts (3) Scripts Interview Questions (2) Scripts-Interview-Questions (32) Search Help Interview Questions (1) Search-Help-Interview-Questions (9) Smartforms (1) Table Maintenance Generator (1) Table-Maintenance-Generator (4) Tables in SAP (2) Tables Interview Questions (3) Tables-Interview-Questions (3) Type Group Interview Questions (1) Type-Group-Interview-Questions (7) Variable Declaration (1) Views Interview Questions (1) Views-Interview-Questions (5) Webdynpro (12) what is big data (1)

Protected Blog

 
This blog is not affiliated to SAP AG |SAP is trademark of SAP AG |The information collected from various sources use information with your own risk.