Inheritance Concept of Inheritance . Types of Inheritance .

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.
Inheritance (2).
Chapter 6 Advanced Function Features Pass by Value Pass by Reference Const parameters Overloaded functions.
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
Review of Inheritance. 2 Several Levels of Inheritance Base Class B Derived class D Derived class D1.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
Inheritance Math 130 B Smith: Consider using the example in SAMS Teach Yourself C++ in 24 hours B Smith: Consider using the example in SAMS Teach Yourself.
Derived Classes. C++ 2 Outline  Definition  Virtual functions  Virtual base classes  Abstract classes. Pure virtual functions.
Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.
Learners Support Publications Inheritance: Extending Classes.
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.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Object Oriented Programming using VC++. Introduction Program – Set of instruction written in a high level language High level language used for writing.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 28P. 1Winter Quarter Inheritance and Overloading.
Inheritance using Java
OOPS. OOPS Concepts Classes Objects Data Abstraction and Encapsulation Inheritance Polymorphism Dynamic Binding Message Passing.
Object-Oriented Programming Session 9 Course : T Programming Language Concept Year : February 2011.
Object-oriented programming: C++ class A { private: …… // can be accessd by A protected: …… // can be accessed by A and // its derived classes public:
Inheritance CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
JAVA WORKSHOP SESSION – 3 PRESENTED BY JAYA RAO MTech(CSE) NEWTON’S INSTITUTE OF ENGINEERING 1.
CS212: Object Oriented Analysis and Design Lecture 15: Inheritance in C++ -II.
INHERITANCE IN C++ Amit Saxena PGT(CS) KV Rangapahar Cantt. (Nagaland)
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Chapter 10 Inheritance and Polymorphism
1 What is the purpose of Inheritance? zSpecialisation Extending the functionality of an existing class zGeneralisation sharing commonality between two.
Inheritance - Multilevel MEENA RAWAT PGT (COMP) KV ONGC Chandkheda 1.
Tracing through E01, question 9 – step 1 // p02.cc P. Conrad, for CISC181 07S // Exam question for E01 #include using namespace std; void mysteryFunction(int.
Computer Programming & Applications Mohamed Iqbal Pallipurath Lecture 02P. 1 Inheritance and Overloading Lecture 28.
Powers and roots. Square each number a) 7 b) 12 c) 20 d) 9 e) 40 a) 49 b) 144 c) 400 d) 81 e) 1600.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MTech[IT],MPhil (Comp.Sci), MCA, MSc[IT], PGDCA, ADCA, Dc. Sc. & Engg.
INHERITANCE : Extending Classes. Rickshaw cart Bus Car Pulled Vehicles Inheritance Inheritance Vehicles Inheritance is the capability of one class of.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Introduction to Object Oriented Programming (OOP) Object Oriented programming is method of programming.
Topics Inheritance introduction
CS1201: Programming Language 2 Classes and objects Inheritance By: Nouf Aljaffan Edited by : Nouf Almunyif.
1 Chapter 7 INHERITANCE. 2 Outlines 7.1 Fundamentals of Inheritance 7.2 The protected Access Specifier 7.3 Constructing and Destroying Derived Classes.
Chapter 9. Inheritance - Basics Inheritance is a mechanism that allows you to base a new class upon the definition of a pre-existing class Subclass inherits.
Types of Inheritance in C++. In C++ we have 5 different types of inheritance: – Single Inheritance – Multiple Inheritance – Hierarchical Inheritance –
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Object Oriented Programming(Objects& Class) Classes are an expanded concept of data structures: like.
Java Inheritance in Java. Inheritance Inheritance is a mechanism in which one object acquires all the properties and behaviors of parent object. The idea.
Classes Sujana Jyothi C++ Workshop Day 2. A class in C++ is an encapsulation of data members and functions that manipulate the data. A class is a mechanism.
Structure A Data structure is a collection of variable which can be same or different types. You can refer to a structure as a single variable, and to.
1 n Object Oriented Programming. 2 Introduction n procedure-oriented programming consists of writing a list of instructions and organizing these instructions.
OBJECT ORIENTED PROGRAMMING WITH C++ Team Members: Lalitha.V.P(Team Head) Manonmani.S Pavithra.H.
Modern Programming Tools And Techniques-I
Inheritance in Java.
Chapter 5 Classes.
Presented By: Nazia Hossain Lecturer, Stamford University
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Object Oriented Analysis and Design
Object Oriented Programming Language (OOP)
HYBRID INHERITANCE : AMBIGUITY REMOVAL
Programming -2 برمجة -2 المحاضرة-7 Lecture-7.
Inheritance.
Pointers & Functions.
Introduction Types Syntax Visibility Modes Example Programs
Testing with OO OO has several key concepts:
By Muhammad Waris Zargar
C++ Inheritance.
Inheritance:Concept of Re-usability
By Rajanikanth B OOP Concepts By Rajanikanth B
Institute of Petroloeum Technology, Gandhinagar
foo.h #ifndef _FOO #define _FOO template <class T> class foo{
B.FathimaMary Dept. of Commerce CA SJC Trichy-02
Pointers & Functions.
OOP Aga private institute for computer science 5th grade
CPS120: Introduction to Computer Science
Inheritance in c++ Introduction
Computer Science II for Majors
Presentation transcript:

Inheritance Concept of Inheritance . Types of Inheritance .

Inheritance Inheritance is a method by which new classes are created or derived from the existing classes. Using Inheritance some qualities of the base classes are added to the newly derived class, apart from its own features The advantage of using "Inheritance" is due to the reusability of classes in multiple derived classes. The ":" operator is used for inheriting a class.

Derived Class Visibility The following table lists the visibility of the base class members in the derived classes   Derived Class Visibility Base Class Visibility Public derivation Private derivation Protected derivation Private Not inherited Protected Public

Following are the different types of inheritance followed in C++. Single Inheritance Multiple Inheritance Hierarchical Inheritance Multilevel Inheritance Hybrid Inheritance

Inheritance: Introduction The inheritance allows subclasses to inherit all properties (variables and methods) of their parent classes. The different forms of inheritance are: Single inheritance (only one super class) Multiple inheritance (several super classes) Hierarchical inheritance (one super class, many sub classes) Multi-Level inheritance (derived from a derived class) Hybrid inheritance (more than two types)

Forms of Inheritance A A B A B C B C D (a) Single Inheritance (b)Multiple Inheritance (c(Hierarchical Inherit. A A c B B C D (d) Multi-Level Inheritance ( e) Hybrid Inheritance

Example: #include <iostream.h> class Value { protected: int val; public: void set_values (int a) { val=a;} }; class Square: public Value int square() { return (val*val); } int main () { Square sq; sq.set_values (5); cout << "The square of 5 is::" << sq.square() << endl; return 0; } Result: The square of 5 is:: 25 In the above example the object "val" of class "Value" is inherited in the derived class "Square".

Explanation Single Inheritance is method in which a derived class has only one base class.

Example: # include <iostream.h> class Value { protected: int val; public: void set_values (int a) { val=a;} }; class Cube: public Value int cube() { return (val*val*val); } int main () { Cube cub; cub.set_values (5); cout << "The Cube of 5 is::" << cub.cube() << endl; return 0; } Result: The Cube of 5 is:: 125 In the above example the derived class "Cube" has only one base class "Value". This is the single inheritance OOP's concept.

Multiple Inheritance Explanation Multiple Inheritance is a method by which a class is derived from more than one base class.

Example: Result: The area of the square is:: 25 int main () { Area r; #include <iostream.h> using namespace std; class Square { protected: int l; public: void set_values (int x) { l=x;} }; class CShow { void show(int i); }; void CShow::show (int i) { cout << "The area of the square is::" << i << endl; } class Area: public Square, public CShow int area() { return (l *l); } int main () { Area r; r.set_values (5); r.show(r.area()); return 0; } Result: The area of the square is:: 25

In the above example the derived class "Area" is derived from two base classes "Square" and "CShow". This is the multiple inheritance OOP's concept in C++.

Hierarchical Inheritance Explanation Hierarchical Inheritance is a method of inheritance where one or more derived classes is derived from common base class.

cout << "The square value is::" << s.sq() << endl; Example: #include <iostream.h> class Side { protected: int l; public: void set_values (int x) { l=x;} }; class Square: public Side { int sq() { return (l *l); } class Cube: public Side public: int cub() { return (l*l*l); } int main () { Square s; s.set_values (10); cout << "The square value is::" << s.sq() << endl; Cube c; c.set_values (20); cout << "The cube value is::" << c.cub() << endl; return 0; } Result: The square value is:: 100 The cube value is::8000

In the above example the two derived classes "Square", "Cube" uses a single base class "Side". Thus two classes are inherited from a single class. This is the hierarchical inheritance OOP's concept in C++.