Classof1 logo
Fax: 1- 425- 458- 9358 | Toll free: 1- 877- 252 - 7763
Bookmark and Share
Forgot Password? Click Here
Register  |  Account

Need help with Computer Science assignment?

Get customized homework help now!

Inheritance

From the existing classes, we can create new classes. The new classes are called derived classes. The existing classes are called base classes. The derived classes inherit all the properties of the base classes plus its own properties. The process of inheritance does not affect the base classes.

Advantages:

  • New classes can be derived from the existing classes without any modification.
  • It saves time and money.
  • It reduces program coding time.
  • It increases the reliability of the program.

Defining Derived classes:

General form:

Class derived_class_name : mode base_class_name

{

new member variable declaration

- -- - -------- -- - -- -- -- - -- - --

-- -- - -- -- -- - -- - -- - -- -- - ---

new member function declaration & definition

- - - -- - - - - -- - - - - - - - - - - - - - - - -

-- - - -- - - -- - -- - - -- -- - -- - -- - -- -

};

Class- keyword.

Derived_class_name – name of the new class. A valid c++ Variable.

Mode  -  private or public. By default it is private.

Base_class_name – name of the already existing classes.

Single inheritance:

  • If a derived class is derived from a single base class then it is called single inheritance. Single inheritance can be derived publicly or privately.
  • If publicly derived, the public and protected member functions of the base class become public and protected in the derived class. If privately derived, the
  • public and protected member function of the base class becomes private in the derived class.

Multilevel inheritance:

It is a process to derive classes in a sequential order. A base class is treated as level 1 class. From this class we can derive a new class and is treated as level2 class. From the level2 class we can derive another new class and is treated as level3 class and so on.

The lower level class inherits the higher level classes along the inheritance path.

Syntax:

Class base

{

-- - -

------

};

class derive1: mode base

{

- -- - --

- - -- - --

};

class derive2: mode derive 1

{

- -- - --

- - -- -

};

Where mode – visibility modifier and can be private or public.

Multiple inheritance:

A class derived from more than one base classes is called multiple inheritance.

General form:

Class base1

{

- -- - --

-- -- - --

};

class base2

{

--- - --

- - -- - --

};

class base3

{

- -- - --

-- -- - --

};

class derived: mode base1, mode base2, mode base3

{

-- - - -- - - -

- -----------

};

mode – visibility modifier and can be private or public.

Hierarchy inheritance:

Hierarchy inheritance is a process to derive classes in a hierarchical order. A base class is treated as level1 class. From this class we can derive new classes and is treated as level2 classes. From a level2 class we can derive other new classes and is treated as level3 and so on. The lower level classes inherit the higher level classes along inheritance path.

Hybrid inheritance – Multilevel, multiple inheritance:

An inheritance class derived from a base class and an inheritance class or two inheritance classes is called hybrid inheritance.

Computer Science Homework Help
Name* :
Email* :
Country* :
Phone* :
Subject* :
Upload Homework :
Upload another homework (upto 5 uploads max.)
Due Date
Time
AM/PM
Timezone
Instructions
(Type Security Code - case sensitive)