Inheritance in C++
Talk to a Teacher
         http://spoken-tutorial.org
National Mission on Education through ICT
            http://sakshat.ac.in
              Ashwini R Patil
               IIT Bombay
            13 December 2012
         December
          Ashwini R Patil 24, 2012
                          Inheritance in C++
Learning Objectives
          Ashwini R Patil   Inheritance in C++
Learning Objectives
I   Inheritance
              Ashwini R Patil   Inheritance in C++
Learning Objectives
I   Inheritance
I   Types of Inheritance
              Ashwini R Patil   Inheritance in C++
Learning Objectives
I   Inheritance
I   Types of Inheritance
I   We will do this with the help of examples
              Ashwini R Patil   Inheritance in C++
System Requirements
         Ashwini R Patil   Inheritance in C++
System Requirements
I   Ubuntu OS v. 11.10
             Ashwini R Patil   Inheritance in C++
System Requirements
I   Ubuntu OS v. 11.10
I   g++ Compiler v. 4.6.1
             Ashwini R Patil   Inheritance in C++
Introduction to Inheritance
           Ashwini R Patil   Inheritance in C++
Introduction to Inheritance
I   When one object acquires the property of
    another it is called as inheritance
              Ashwini R Patil   Inheritance in C++
Introduction to Inheritance
I   When one object acquires the property of
    another it is called as inheritance
I   It is the process of reusing the existing
    class without modifying them
              Ashwini R Patil   Inheritance in C++
Types of Inheritance
          Ashwini R Patil   Inheritance in C++
Types of Inheritance
I   Single level inheritance
               Ashwini R Patil   Inheritance in C++
Types of Inheritance
I   Single level inheritance
I   Multiple level inheritance
               Ashwini R Patil   Inheritance in C++
Types of Inheritance
I   Single level inheritance
I   Multiple level inheritance
I   Hierarchical Inheritance
               Ashwini R Patil   Inheritance in C++
Types of Inheritance
I   Single level inheritance
I   Multiple level inheritance
I   Hierarchical Inheritance
I   Multilevel inheritance
               Ashwini R Patil   Inheritance in C++
Types of Inheritance
I   Single level inheritance
I   Multiple level inheritance
I   Hierarchical Inheritance
I   Multilevel inheritance
I   Hybrid Inheritance
               Ashwini R Patil   Inheritance in C++
Base class and Derived class
          Ashwini R Patil   Inheritance in C++
Base class and Derived class
I   The base class has its own properties and
    functionality
              Ashwini R Patil   Inheritance in C++
Base class and Derived class
I   The base class has its own properties and
    functionality
I   It is also called as parent class
              Ashwini R Patil   Inheritance in C++
Base class and Derived class
I   The base class has its own properties and
    functionality
I   It is also called as parent class
I   It has the common qualities that all the
    objects can inherit
              Ashwini R Patil   Inheritance in C++
Base class and Derived class
I   The base class has its own properties and
    functionality
I   It is also called as parent class
I   It has the common qualities that all the
    objects can inherit
I   The derived class is the child class
              Ashwini R Patil   Inheritance in C++
Base class and Derived class
I   The base class has its own properties and
    functionality
I   It is also called as parent class
I   It has the common qualities that all the
    objects can inherit
I   The derived class is the child class
I   Derived class inherits the properties and
    functionality of the base class
              Ashwini R Patil   Inheritance in C++
Single inheritance
           Ashwini R Patil   Inheritance in C++
Single inheritance
I   In single level inheritance only one base
    class and one derived class is needed
                      Base Class
                   Derived Class
               Ashwini R Patil   Inheritance in C++
Multiple inheritance
           Ashwini R Patil   Inheritance in C++
Multiple inheritance
I   In multiple inheritance derived class
    inherits from more than one base class
      Base Class                Base Class2
              Derived Class
              Ashwini R Patil   Inheritance in C++
Hierarchical inheritance
           Ashwini R Patil   Inheritance in C++
Hierarchical inheritance
I   In Hierarchical Inheritance multiple
    derived class inherits from one base
      Base Class
        Derived        Derived             Derived
        Class1         Class2              Class3
              Ashwini R Patil   Inheritance in C++
Multilevel inheritance
           Ashwini R Patil   Inheritance in C++
Multilevel inheritance
I   In Multilevel inheritance the subclass acts
    as the base class for other classes
                      Base Class
                   Base/Derived
                       Class
                   Derived Class
               Ashwini R Patil   Inheritance in C++
Hybrid inheritance
          Ashwini R Patil   Inheritance in C++
Hybrid inheritance
I   In hybrid inheritance more than one form
    of inheritance is combined
              Ashwini R Patil   Inheritance in C++
Summary
I   Inheritance
I   Types of inheritance
              Ashwini R Patil   Inheritance in C++
Assignment
I   Create a class Shape
I   Create two functions of the class as Area
    and Perimeter
I   Find the area and perimeter of various
    shapes like square, rectangle and circle
              Ashwini R Patil   Inheritance in C++
About the Spoken Tutorial Project
I   Watch the video available at
    http://spoken-tutorial.org
    /What is a Spoken Tutorial
I   It summarises the Spoken Tutorial project
              Ashwini R Patil   Inheritance in C++
About the Spoken Tutorial Project
I   Watch the video available at
    http://spoken-tutorial.org
    /What is a Spoken Tutorial
I   It summarises the Spoken Tutorial project
I   If you do not have good bandwidth, you
    can download and watch it
              Ashwini R Patil   Inheritance in C++
 Spoken Tutorial Workshops
The Spoken Tutorial Project Team
 I Conducts workshops using spoken
   tutorials
 I Gives certificates to those who pass an
   online test
 I For more details, please write to
     contact@spoken-tutorial.org
              Ashwini R Patil   Inheritance in C++
Acknowledgements
I   Spoken Tutorial Project is a part of the
    Talk to a Teacher project
I   It is supported by the National Mission
    on Education through ICT, MHRD,
    Government of India
I   More information on this Mission is
    available at:
     http://spoken-tutorial.org
     /NMEICT-Intro
              Ashwini R Patil   Inheritance in C++