Ans: Inheritance
Inheritance is taken in the sense of code reuse within the object
oriented development. During modeling, we look at the resulting classes, and
try to group similar classes together so that code reuse can be enforced.
Generalization, specialization, and inheritance have very close association.
Generalization is used to refer to the relationship among classes, and
inheritance is used for sharing attributes and operations using the
generalization relationship. In respect of inheritance, generalization and
specialization are two phases of a coin in the sense that if a subclass is seen
from a superclass the subclass is seen as a specialized version of superclass
and in, reverse, a superclass looks like general form of subclass.
During inheritance, a subclass may override a superclass feature
by defining that feature with the same name. The overriding features (the
subclass feature with the same names of superclass features) refines and
replaces the overridden feature (the superclass feature).
There are 5 types of inheritance-
1.
single level inheritance
2.
multilevel inheritance
3.
multiple inheritance
4.
hybrid inheritance
5.
hierarchical inheritance.
Advantages of inheritance-
·
Reusability - facility to use public methods of base class without rewriting
the same.
·
Extensibility - extending the base class logic as per business logic of the
derived class.
·
Data hiding - base class can decide to keep some data private so that it
cannot be altered by the derived class
·
Overriding -With inheritance, we will be able to override the methods of the base
class so that meaningful implementation of the base class method can be
designed in the derived class.
0 comments:
Post a Comment
Let us know your responses and feedback