Ads

ABAP OOPs Interview Questions Part Three

ABAP OOPs Interview Questions Part Three


Dear friends ,in the previous lessons we have learnt ABAP OOPs Inteview questions and Part one and Part two OOPS interview questions and Now we learn more Part three OOPs interview questions which are useful for freshers and senior ABAP and Webdynpro Consultants.


Brief about Object Oriented Programming In SAP ABAP?


The object-oriented approach, however, focuses on objects that represent abstract or concrete things of the real world. These objects are first defined by their character and their properties which are represented by their internal structure and their attributes (data). The behavior of these objects is described by methods (functionality).

Objects
Objects are instances of classes. They contain data and provides services. The data forms the attributes of the object.
Classes
Classes describe objects. From a technical point of view, objects are run time instances of a class. In theory, you can create any number of objects based on a single class.
Object References
In a program, you identify and address objects using unique object references.
Encapsulation
Objects restrict the visibility of their resources (attributes and methods) to other users.
Inheritance
You can use an existing class to derive a new class.
Polymorphism
Identical (identically-named) methods behave differently in different classes.

What are the Advantages Object oriented programming In ABAP?

 Complex software systems become easier to understand
 it should be possible to implement changes at class level
Through polymorphism and inheritance, object-oriented programming allows you to reuse individual components.
  In an object-oriented system, the amount of work involved in revising and maintaining the system is reduced

What are the characteristics of object?

It has a state.
It has a unique Identity.
It has the behaviour.

How do you create an Object?


DATA: <object_name> TYPE REF TO <class_name>.

CREATE Object: <object_name>.


What is the syntax of class?

CLASS <class_name> DEFINITION.
..........
..........
ENDCLASS.


What is the syntax of class implementation?

CLASS <class_name> IMPLEMENTATION.
...........
..........
ENDCLASS.

What are the attributes in class?


Attributes are data fields of a class that can have any data type such as C, I, F, and N.

What is Instance attribute?

An instance attribute defines the instance specific state of an object.

What is static attribute?

Static attributes define a common state of a class that is shared by all the instances of the class.


What is a Method of a class?

A method is a function or procedure that represents the behaviour of an object in the class.

How do you define Method?

METHOD <m_name>.
..........
..........
ENDMETHOD.

What are the access properties of attributes and methods ?

The attributes and methods declared in Public section in a class can be accessed by that class and any other class, sub-class of the program.

When the attributes and methods are declared in Protected section in a class, those can be accessed by that class and sub classes (derived classes) only.

When the attributes and methods are declared in Private section in a class, those can be accessed by only that class and not by any other class.

What is constructor in a Class?

Constructors are special methods that are called automatically, either while creating an object or accessing the components of a class.


What are the main properties of inheritance?

An object of one class can acquire the properties of another class.

Derived class inherits the data and methods of a super class. However, they can overwrite methods and also add new methods.

The main advantage of inheritance is re usability.

What is syntax of Inheritance?

CLASS <subclass> DEFINITION INHERITING FROM <super class>.

How do you create an interface?
INTERFACE <intf_name>.
DATA.....
CLASS-DATA.....
METHODS.....
CLASS-METHODS.....
ENDINTERFACE.


How do you access interface in the class?

INTERFACE <intf_name>.
How do you implement interface method in within the class?
METHOD <intf_name~method_m>.
<statements>.
ENDMETHOD.

What is an Event in OO ABAP?

An event is action that are defined in a class to trigger the event handlers in other classes. When an event is triggered, we can call any number of event handler methods. The link between a trigger and its handler method is actually decided dynamically at run-time.

Declare the event in its declaration part
Trigger the event in one of its methods


How do you declare events?

EVENTS evt EXPORTING... VALUE(e1 e2 ...) TYPE type [OPTIONAL]..
CLASS-EVENTS evt..

How event is triggered in the class?

RAISE EVENT evt EXPORTING e1 = f1  e2 = f2 ...

How do you declare event handler methods?


METHODS meth FOR EVENT evt OF cif IMPORTING e1 e2 ...

How you register event handler methods?

SET HANDLER h1 h2 ... FOR ALL INSTANCES.
SET HANDLER h1 h2 ... FOR ref.
How do you define static and instance methods in the class?
Instance Methods
You declare instance methods using the METHODSstatement.
Static Methods
You declare static methods using the CLASS-METHODSstatement.

What are the main components of the class?

 A class contains components
Each component is assigned to a visibility section
Classes implement methods


How do you access the components of the objects within the class?


We access an attribute attr: ref->attr
We call a method meth: CALL METHOD ref->meth
 We access a static attribute attr: class=>attr
We call a static method meth: CALL METHOD class=>meth


 We access an attribute attr of your class: me->attr
We call a method meth of your class: CALL METHOD me->meth


What is the life time of object?

An object exists for as long as it is being used in the program. An object is in use by a program for as long as at least one reference points to it, or at least one method of the object is registered as an event handler.
As soon as there are no more references to an object, and so long as none of its methods are registered as event handlers, it is deleted by the automatic memory management (garbage collection).

Comments

Popular posts from this blog

BADI Interview Questions in SAP ABAP

Sample SAP ABAP Programming Examples for Practice

Module Pool Programming Interview Questions and Answers in SAP ABAP

Step by Step tutorial on BDC Session Method Program in SAP ABAP

SAP ABAP Interview Questions and Answers for 10 Years Experienced