SAP-ABAP Inheritance Interview Questions Answers, Inheritance is the main feature of Object Oriented Programming in any Object Oriented Language, like OOABAP also contains Inheritance feature to extend the functionality of language of SAP-ABAP. Here in this post we are going to provide list of interview questions and also answers on Inheritance topic. These questions are very frequently asked by the interviewers in the interviews. Click on read more to refer this post.
SAP-OOABAP-Inheritance-Interview-Questions-Answers
SAP-ABAP Inheritance Interview Questions Answers, Inheritance is the main feature of Object Oriented Programming in any Object Oriented Language, like OOABAP also contains Inheritance feature to extend the functionality of language of SAP-ABAP. Here in this post we are going to provide list of interview questions and also answers on Inheritance topic. These questions are very frequently asked by the interviewers in the interviews.
1) What is inheritance?
Ans)
Inheritance allows you to derive a new class from an
existing class. You do this using the INHERITING FROM addition in the CLASS subclass DEFINITION
INHERITING FROM superclass statement.
2) What are the visibility sections visible to subclass of
superclass?
Ans)
Only the public and protected components of the superclass
are visible in the subclass.
3)
Can we declare same name for components of subclass as components of super
class?
Ans)
Subclasses contain all of the components of all of their superclasses within
the inheritance tree. Only the public and protected ones are visible. All
public and protected components within an inheritance tree belong to the same
namespace, and consequently must have unique names. The names of private
components, on the other hand, must only be unique within their class.
4)
What is single inheritance?
Ans)
A class can have more than one direct subclass, but
it may only have one direct superclass. This is called single inheritance.
5) Does OOABAP supports multiple inheritance?
Ans)
No, OOABAP does not support multiple inheritance but
it supports multi level inheritance.
6) What is the root node of all inheritance
trees?
Ans)
The root node of all inheritance trees
in ABAP Objects is the predefined empty class OBJECT. This is the most generalized
class possible, since it contains neither attributes nor methods.
When you
define a new class, you do not have to specify it explicitly as the super class
- the relationship is always implicitly defined.
7) How can we re-implement super class
method in subclass?
Ans)
Super class method can be
re-implemented in the derived class using redefinition key word.
8) Can we change the parameter interface of
the redefined methods?
Ans)
No, we cannot change the parameter interface
of the redefined methods.
9) How to call original method from
redefined method?
Ans)
In the redefined method use the
SUPER-> pseudo reference to access the original method of the base class.
10) What is an abstract class?
Ans)
A class defined as ABSTRACT cannot be
instantiated, that is one cannot use CREATE OBJECT with reference to the class.
To use the instance components of an abstract class, a subclass of the class
must be instantiated.
11) Can abstract methods be redefined?
Ans)
Yes, abstract methods should be
redefined in the subclass. Else it gives syntax error. If subclass is also
abstract classes then no need to redefine the abstract method.
12) Can final class methods be redefined in
the subclass?
Ans)
A final method cannot be redefined in
a subclass. Final classes cannot have sub classes. They conclude an inheritance
tree.
13) Can static method be redefined?
Ans) No, static methods cannot be
redefined.
14) Can we change the visibility of the
redefined method?
Ans)
No, we cannot change the visibility of
the redefined method. That is , if method is defined in super class in public
section then we cannot redefine the same method in the subclass under protected
or private.
15) Can the private and protected classes
can be inherited?
Ans)
Yes, we can inherit the private and
protected classes. Then the subclass itself becomes the private or protected
class.
16) Does the instantiation of Subclass
depend on the super class?
Ans)
Where a subclass can be instantiated
depends on its immediate super class:
i. Immediate
sub classes of object, or classes
with the CREATE PUBLIC addition
implicitly inherit the CREATE PUBLIC
addition. All CREATE additions
that overwrite the inherited addition can be specified explicitly.
ii. Immediate sub classes
of classes with the CREATE PROTECTED addition implicitly inherit the CREATE
PROTECTED addition. All CREATE additions that overwrite the inherited addition
can be specified explicitly.
iii. Immediate
sub classes of classes with the CREATE PRIVATE addition that are not friends of the class implicitly
receive the CREATE NONE addition. They cannot be instantiated and you cannot
specify any explicit CREATE additions for them.
iv. Immediate
sub classes that are friends of the class implicitly inherit the CREATE PRIVATE addition. All CREATE additions can be specified for
all super classes that can instantiated as private using friends.
17) Can the constructor be redefined?
Ans)
No, we cannot redefine the instance constructor of a super class in a
subclass, neither can you call one specifically using the statement CALL METHOD CONSTRUCTOR.
18) Does the parameter interface of the
instance constructor be changed in the subclass?
Ans)
The parameter interface for instance constructor
of each class may be different in an inheritance tree.
19) Do we need to call the super class
instance constructor in the subclass when instance constructor is redefined?
Ans)
During implementation of redefined instance constructor in derived class
, the instance constructor of the super class must be called with the
CALL METHOD SUPER->constructor … EXPORTING
… statement.
20) In which order the constructors execute
in inheritance tree?
Ans)
The first time a subclass is addressed
in a program, the run time environment reaches for the next highest super class
whose constructor has not yet been executed.
This constructor is executed
first, followed by constructors down the path until the addressed subclass is
reached.
21) Can we call the instance constructor of
the super class in sub class?
Ans)
Yes, we can call the instance
constructor of the super class explicitly in subclass instance constructor
using Pseudo reference (SUPER->).
This
is the only place where we call the constructor explicitly.
22) Can we call the static constructor of
the super class in sub class?
Ans)
NO, we cannot call the static
constructor explicitly. The runtime environment automatically ensures that the
static constructors are called in the right order, so it is not required to
call the static constructor of the super class explicitly.
23) What is polymorphism?
Ans)
When objects from different classes
react differently to the same method calls, this is know as polymorphism. This is achieved through inheritance and
interfaces.
24)
What is Narrowing cast(Upcast)? Explain briefly?
Ans)
Assigning sub class reference to super
class reference. Syntax for narrowing cast is ‘=’ or ‘MOVE’ …‘TO’. If you
assign a sub class reference to a super class reference, this ensures that all
components that can be accessed syntactically after the cast assignment are
actually available in the instance.
The subclass always contains at least the
same components as the super class.
25) What is the use of Narrowing cast?
Ans)
Typical use of narrowing cast
assignment is to prepare for generic access. A user who is not at all
interested in the finer points of the instances of the sub classes but who
simply wants to address the shared components could use a super class reference
for this access.
26) Which components of sub class can be
accessed from super class reference using narrowing cast?
Ans)
Only the inherited components can be
accessed from super class reference after narrowing cast.
27) What is Widening cast ( Down casting)?
Ans)
Assigning super class reference to sub
class reference. Syntax for widening
cast is ‘?=’ or ‘MOVE’…’?TO’.
28) What is the use of Widening cast?
Ans)
Typical use of for widening cast
assignments is when specific components of instances need to be addressed and
their references are kept in variables that are typed on the super class.
A
user who is interested in the finer points of the instances of a subclass
cannot use the super class reference for this access because it only allows
access to the shared components.
Dear ABAPers if you know any other questions please share your views in 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.