• Like
Inheritance in oops
Upcoming SlideShare
Loading in...5
×

Inheritance in oops

  • 988 views
Uploaded on

Describes inheritance in object oriented programming in general and in Java, C++, Python and ADA in particular

Describes inheritance in object oriented programming in general and in Java, C++, Python and ADA in particular

More in: Software , Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
988
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
68
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Sharda University Department Of Computer Science And Engineering School Of Engineering And Technology Greater Noida, U. P.
  • 2. Presented By Hirra Sultan CSE-B 2nd year Roll No. 120101091 Enrollment No. 2012017740 Supervisor: Mr. A. K. Sahoo prlhirr@gmail.com
  • 3. 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.
  • 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 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.
  • 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 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.
  • 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 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.
  • 16. Disadvantages  Removing or swapping out a superclass will usually break subclasses.  It's inflexible.  Inheritance relationships generally can't be altered at runtime.