3.sap OOPS-Inhitence, Polymohrishm, Enchapsulation
3.sap OOPS-Inhitence, Polymohrishm, Enchapsulation
3.sap OOPS-Inhitence, Polymohrishm, Enchapsulation
· We can use inheritance while writing a class with which to derive a parent class, by mentioning
the name of parent class in the definition of derived class
· Hence, the class that is inherited is called parent or base class or super class, and the class
inheriting the base class is the child class or derived class or subclass
· Through inheritance, an object from derived class can obtain characteristics of objects from base
class
· The keyword to use for inheritance is ‘INHERITING FROM’, just beside the class definition
Report name:ZDATAFLAIR_INHERITANCE
Output:
· So when a subclass inherits a superclass, there are certain rules that govern how the class can
access objects and data of superclass
The following table shows whether a derived class has access to base class, based on whether the base
class is defined as public/protected/private:
PROTECTED Yes No No
1. Public Inheritance:
· Public data and members of superclass become public data and members of subclass
2. Private Inheritance:
3. Protected Inheritance:
· However, we must keep the section of redefinition of the method the same as the parent
method
· We only need to use the name of the inherited method and can access its components using
‘super’ reference
Encapsulation in ABAP
· This hides the data and function from the outside world, thus promoting data hiding
· Data hiding means obstructing the view of private data and functions from unwanted
third parties, and data abstraction means showing users only what they need to see
· We can also perform encapsulation via interfaces (which are similar to classes, the only
difference is that we do not implement anything in an interface, it has to be done via
class inheriting the interface, as shown in example below)
Output:
Polymorphism in SAP ABAP
· It means using one thing for different operations
· It occurs usually in inheritance – for e.g. redefining methods which we saw under the
concept of inheritance
· Overloading methods means when we use the same method name but use different
parameters
· Overriding methods means when we use the same method name and parameters, but
the two methods are related via inheritance relationship
Report name:ZDATAFLAIR_POLYMIRPHISM
Output: