Sharda University
Department Of Computer Science And Engineering
School Of Engineering And Technology
Greater Noida, U. P.
Presented By
Hirra Sultan
CSE-B 2nd year
Roll No. 120101091
Enrollment No. 2012017740
Supervisor: Mr. A. K. Sahoo
prlhirr@gmail.com
Introduction
Background
 The first OOP language designed for the
first personal computer was smalltalk.
 When OOP was integrated into C
language, the resulting language was
called C++ and it became the first object-
oriented language to be widely used
commercially.
 Later java and other OOP languages were
developed.
Concept of Inheritance
 Inheritance is that feature of an OOP language
which allows reusability of code of a class and
is considered corner stone of OOP languages.
 Using inheritance, we can create a general
class that defines traits common to a set of
related items.
 This class may then be inherited by other,
more specific classes, each adding only those
things that are unique to the inheriting class.
 Base class: The class which gets inherited is
called a base class. The code of this class is
passed on to subclasses where it is reused.
 Derived class: A subclass is a derived class
which inherits the base class and uses its
member functions.
 Un-inheritable class: A class may be
declared as un-inheritable by adding certain class
modifiers to the class declaration before the
"class" keyword and the class identifier
declaration. Such sealed classes
restrict reusability.
Definitions
Types of Inheritance
 Single Inheritance: In single
inheritance there is only one super class
and only one sub class.
 Multi-level inheritance: In multi-level
inheritance a derived class is inherited by
another class thus making multiple levels.
 Multiple Inheritance: A class can inherit
the attributes of two or more classes. This
is known as multiple inheritance.
 Hierarchical inheritance: When a base
class is inherited by multiple derived
classes it is called hierarchical inheritance.
 Hybrid inheritance: This is a mixture of
two or more inheritances in a single code.
Inheritance may be derived in three forms
which decides the way inherited data
members can be used.
 Public Inheritance: Public members of
the base class become public members of
the derived class and protected members
of the base class
become protected members of the derived
class.
 Protected Inheritance: When
deriving from a protected base class, public
and protected members of the base class
become protected members of the derived
class.
 Private Inheritance: When deriving
from a private base class, public and
protected members of the base class
become private members of the derived
class.
Inheritance in C++
 In C++ all the five types of inheritances are
applicable.
 Friend functions and constructors can’t be
inherited.
 The general syntax of inheritance is:
class derived-class-name : visibility-mode base-
class-name
{
…// members of derived class
};
Inheritance in Java
 The general syntax of inheritance is:
Class Subclass-name extends superclass-
name
{
//methods and fields
}
 The keyword extends indicates that we are
making a new class that derives from an
existing class.
 Multiple and hybrid inheritance is not
supported. This reduces the program
complexity.
 Constructors are not inherited by a subclass.
Inheritance in Python
 Instances inherit from classes, and classes
inherit from super classes.
 Python supports a limited form of multiple
inheritance.
 The syntax for inheritance in python is:
class DerivedClassname
(BaseClassName):
<statement-1>
.
<statement-N>
Inheritance in ADA
 In Ada 95 terminology, types that can have
parents or children are termed “tagged
types”, and have the keyword “tagged” as
part of their definition.
 If we don't redefine a subprogram for a
given type, the closest ancestor's defined
subprogram will be used.
Advantages
 We save time because much of the code
needed for our class is already written.
 We can extend and revise a parent class
without corrupting the existing parent class
features.
Disadvantages
 Removing or swapping out a superclass
will usually break subclasses.
 It's inflexible.
 Inheritance relationships generally can't
be altered at runtime.
Inheritance in oops

Inheritance in oops

  • 1.
    Sharda University Department OfComputer Science And Engineering School Of Engineering And Technology Greater Noida, U. P.
  • 2.
    Presented By Hirra Sultan CSE-B2nd year Roll No. 120101091 Enrollment No. 2012017740 Supervisor: Mr. A. K. Sahoo prlhirr@gmail.com
  • 3.
    Introduction Background  The firstOOP language designed for the first personal computer was smalltalk.  When OOP was integrated into C language, the resulting language was called C++ and it became the first object- oriented language to be widely used commercially.  Later java and other OOP languages were developed.
  • 4.
    Concept of Inheritance Inheritance is that feature of an OOP language which allows reusability of code of a class and is considered corner stone of OOP languages.  Using inheritance, we can create a general class that defines traits common to a set of related items.  This class may then be inherited by other, more specific classes, each adding only those things that are unique to the inheriting class.
  • 5.
     Base class:The class which gets inherited is called a base class. The code of this class is passed on to subclasses where it is reused.  Derived class: A subclass is a derived class which inherits the base class and uses its member functions.  Un-inheritable class: A class may be declared as un-inheritable by adding certain class modifiers to the class declaration before the "class" keyword and the class identifier declaration. Such sealed classes restrict reusability. Definitions
  • 6.
    Types of Inheritance Single Inheritance: In single inheritance there is only one super class and only one sub class.  Multi-level inheritance: In multi-level inheritance a derived class is inherited by another class thus making multiple levels.
  • 7.
     Multiple Inheritance:A class can inherit the attributes of two or more classes. This is known as multiple inheritance.  Hierarchical inheritance: When a base class is inherited by multiple derived classes it is called hierarchical inheritance.  Hybrid inheritance: This is a mixture of two or more inheritances in a single code.
  • 8.
    Inheritance may bederived in three forms which decides the way inherited data members can be used.  Public Inheritance: Public members of the base class become public members of the derived class and protected members of the base class become protected members of the derived class.
  • 9.
     Protected Inheritance:When deriving from a protected base class, public and protected members of the base class become protected members of the derived class.  Private Inheritance: When deriving from a private base class, public and protected members of the base class become private members of the derived class.
  • 10.
    Inheritance in C++ In C++ all the five types of inheritances are applicable.  Friend functions and constructors can’t be inherited.  The general syntax of inheritance is: class derived-class-name : visibility-mode base- class-name { …// members of derived class };
  • 11.
    Inheritance in Java The general syntax of inheritance is: Class Subclass-name extends superclass- name { //methods and fields }
  • 12.
     The keywordextends indicates that we are making a new class that derives from an existing class.  Multiple and hybrid inheritance is not supported. This reduces the program complexity.  Constructors are not inherited by a subclass.
  • 13.
    Inheritance in Python Instances inherit from classes, and classes inherit from super classes.  Python supports a limited form of multiple inheritance.  The syntax for inheritance in python is: class DerivedClassname (BaseClassName): <statement-1> . <statement-N>
  • 14.
    Inheritance in ADA In Ada 95 terminology, types that can have parents or children are termed “tagged types”, and have the keyword “tagged” as part of their definition.  If we don't redefine a subprogram for a given type, the closest ancestor's defined subprogram will be used.
  • 15.
    Advantages  We savetime because much of the code needed for our class is already written.  We can extend and revise a parent class without corrupting the existing parent class features.
  • 16.
    Disadvantages  Removing orswapping out a superclass will usually break subclasses.  It's inflexible.  Inheritance relationships generally can't be altered at runtime.