Page 188 - DCAP404 _Object Oriented Programming
P. 188
Unit 9: Inheritance
Notes
Example: If two base classes have a member with the same name, the derived class
cannot implicitly differentiate between the two members. Note that, when you are using multiple
inheritance, the access to names of base classes may be ambiguous.
9.2.4 Hierarchical Inheritance
Another interesting application of inheritance is to use is as a support to a hierarchical design of
a class program. Many programming problems can be cast into a hierarchy where certain
features of one level are shared by many others below that level for e.g.
Accounts
Saving Accounts Current Accounts
Fixed deposit
Short term Long term
Mid term
In general the syntax is given as
Class A
{
//body
A
}
Class B : Class C :
public A public A
{ {
//bodyB //bodyB
} }
In C++, such problems can be easily converted into hierarchies. The base class will include all
the features that are common to the subclasses. A sub-class can be constructed by inheriting the
features of base class and so on.
LOVELY PROFESSIONAL UNIVERSITY 181