1 What is the purpose of Inheritance? zSpecialisation Extending the functionality of an existing class zGeneralisation sharing commonality between two.

Slides:



Advertisements
Similar presentations
Chapter 5 Inheritance. Objectives Introduction, effects, and benefits of inheritance Base class and derived class objects Base class and derived class.
Advertisements

1 Inheritance Classes and Subclasses Or Extending a Class.
Abteilung für Telekooperation Softwareentwicklung 2 UE SE2UE_ Vererbung (Inheritance)
CLASS INHERITANCE Class inheritance is about inheriting/deriving properties from another class. When inheriting a class you are inheriting the attributes.
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
Inheritance. Many objects have a hierarchical relationship –Examples: zoo, car/vehicle, card game, airline reservation system Inheritance allows software.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
C++ Classes & Data Abstraction
Classes and SubClasses Super Parent Sub Child IS - A.
LOGO Lecturer: Abdullahi Salad Abdi May 1, Object Oriented Programming in C++
Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.
INHERITANCE By: Er. Gurpreet Singh Assistant Professor Department of Information Technology, Department of Information Technology, MIMIT Malout 1.
Learners Support Publications Inheritance: Extending Classes.
Chapter 10: Introduction to Inheritance
Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class.
Interface & Abstract Class. Interface Definition All method in an interface are abstract methods. Methods are declared without the implementation part.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
Inheritance using Java
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Learners Support Publications Pointers, Virtual Functions and Polymorphism.
Chapter 15 – Inheritance, Virtual Functions, and Polymorphism
1 What is Inheritance? zThe mechanism of deriving a new class from an old one is called inheritance zClasses organised into a ‘classification hierarchy’
1 Understanding Inheritance COSC 156 C++ Programming Lecture 8.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Unit IV Unit IV: Virtual functions concepts, Abstracts classes & pure virtual functions. Virtual base classes, Friend functions, Static functions, Assignment.
CS212: Object Oriented Analysis and Design Lecture 15: Inheritance in C++ -II.
1 Object Oriented Programming Development - Week7 z Rob Manton z z Room D104.
Inheritance - Multilevel MEENA RAWAT PGT (COMP) KV ONGC Chandkheda 1.
Chapter 7 Understanding Inheritance. LOGO Objectives  Learn about inheritance and its benefits  Create a derived class  Learn about restrictions imposed.
Inheritance: Base and Derived Classes. Introduction In dictionary inheritance is defined as the action of inheriting; the transfer of property; to receive.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
INHERITANCE : Extending Classes. Rickshaw cart Bus Car Pulled Vehicles Inheritance Inheritance Vehicles Inheritance is the capability of one class of.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
Class and Structure. 2 Structure Declare using the keyword struct purpose is to group data Default visibility mode is public A struct doesn't have a constructor.
Inheritance and Composition Reusing the code and functionality Unit - 04.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
© 2007 Lawrenceville Press Slide 1 Chapter 9 Inheritance  One class is an extension of another.  Allows a class to define a specialized type of an existing.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Inheritance Inheritance is the process of extending the functionality of a class by defining a new class that inherit,all the features of extending class.
Types of Inheritance in C++. In C++ we have 5 different types of inheritance: – Single Inheritance – Multiple Inheritance – Hierarchical Inheritance –
Java Inheritance in Java. Inheritance Inheritance is a mechanism in which one object acquires all the properties and behaviors of parent object. The idea.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
 Virtual Function Concepts: Abstract Classes & Pure Virtual Functions, Virtual Base classes, Friend functions, Static Functions, Assignment & copy initialization,
SUBCLASSES - JAVA. The Purpose of Subclasses Class Farm String getOwner() void setOwner(String s) int getSize() void setSize(int s) Class DairyFarm String.
Seventh step for Learning C++ Programming CLASS Declaration Public & Private Constructor & Destructor This pointer Inheritance.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
Programming in Java, 2e Sachin Malhotra Saurabh Choudhary.
Inheritance and Polymorphism
Introduction to Programming with Java
Table of Contents Class Objects.
Object Oriented Analysis and Design
Inheritance Dr. Bhargavi Goswami Department of Computer Science
Polymorphism CT1513.
Java Programming, Second Edition
C++ Inheritance.
Inheritance:Concept of Re-usability
Inheritance and Polymorphism
Institute of Petroloeum Technology, Gandhinagar
B.FathimaMary Dept. of Commerce CA SJC Trichy-02
C++ Programming CLASS This pointer Static Class Friend Class
Constructor, Destructor Mehroz Sadiq CS Faculty, UMT Department of CS&E, UET.
Types of Computer Languages
Extending Classes Through Inheritance
Computer Science II for Majors
Presentation transcript:

1 What is the purpose of Inheritance? zSpecialisation Extending the functionality of an existing class zGeneralisation sharing commonality between two or more classes zImproved efficiency and greater robustness zPlays a major part in polymorphism

2 Inheritance types in C++ 1.Single level Inheritance 2.Multilevel Inheritance 3.Multiple Inheritance 4.Hierarchical Inheritance 5.Hybrid Inheritance

3 Single Inheritance zInheriting the properties of one Derived class from only one Base class is known as Single Inheritance. Base Class Derived Class

Single Inheritance 4 class A { // Base Class A }; class B: public A //Derived Class B { };

Multilevel Inheritance 5 zWhen Single level inheritance is extended to more levels then it is called multilevel inheritance. zIn this inheritance one class is derived from another derived class and the level of derivation can be extended to any number of levels.

Multilevel Inheritance 6 Base Class Intermediate Base Class Derived Class class A { // Base Class A }; class B: public A //Intermediate Base Class B { }; class C: public B // C Derived Class from B { }; The class B is known as intermediate base class since it provides a link for the inheritance between A and C. The chain ABC is known as inheritance path.

Multiple Inheritance Inheriting the properties of the Derived class from more than one Base Class is known as Multiple Inheritance. Derived Class Base Clas 1 Base Class 2 Base Class n

Multiple Inheritance class A { // Base Class A }; class B //Base Class B { }; class C: public A, B // C Derived Class from A and B { };

Hierarchical Inheritance In Hierarchical Inheritance, many sub classes inherit the properties from a single base class. The base class will include all the features that are common to the subclasses. A subclass can be constructed by inheriting the all or some properties of the base class. A subclass can serve as a base class for the lower level classes and so on.

Hierarchical Inheritance Base Class Sub Class Sub class class A { // Base Class A }; class B: public A // Derived Class B { }; class C: public A // C Derived Class { };

Hybrid Inheritance Applying two or more types of inheritance for designing the program is known Hybrid Inheritance.

CM Single inheritance A single inheritance contains only one derived class and one base class

CM Single inheritance The declaration of derived class is same as ordinary class A derived class contains of the following components

CM Single inheritance The keyword class The name of the Derived class A single colon

CM Single inheritance The type of derivation (private, public or protected) The name of the base or parent class The reminder of the class definition

CM Single inheritance BASE CLASS DERIVED CLASS

CM SYNTAX: class derived_classname:visibilitymode base_classname { …………………. members of derived class …………… ……………… }; Single inheritance

CM Single inheritance : Syntax class A { ………………… members of base class A …………………. } class B: public A { ……………. members of derived class B …………… }

CM Program for single inheritance class person { char name[10]; int age; char gender; public: void get data(); void display(); };

CM Program for single inheritance void person ::get data() { cout<<“enter the name”; cin>>name; cout<<“enter the age”; cin>>age; cout<<“enter the gender”; cin>>gender; }

CM Program for single inheritance void person :: display() { cout<<“the name of the student is “<<name; cout<<“the age of the student is “<<age; cout<<“the gender of the student is “<<gender; }

CM Program for single inheritance class student : public person { int roll, no; char branch[10]; public: void get data() { person :: getdata(); cout<<enter the roll no”; cin>>roll,no; cout<<“enter branch”; cin>>branch; }

CM Program for single inheritance void display() { person :: display(); cout<<“the roll no is”<<roll, no; cout<<“the branch is “<<branch; } }; void main() { student s; s.getdata(); s.display(); }

24 Summary: Inheritance zInheriting from a class doesn’t affect the integrity of that class - objects of the original base class can still be created zGeneralisation allows removal of redundancy and duplication among classes zSome base classes are abstract - they are not specific enough to be instantiated but act as holders for common attributes and methods of derived classes

25 Summary: Inheritance zIn C++ the protected keyword allows methods of a derived class access to its inherited attributes zBase class constructor methods are automatically called by the constructors of derived classes but argument lists must be compatible zDestructors are called in the reverse order of constructors