Inheritance - Multilevel MEENA RAWAT PGT (COMP) KV ONGC Chandkheda 1.

Slides:



Advertisements
Similar presentations
Object Oriented Programming
Advertisements

Chapter 5 Inheritance. Objectives Introduction, effects, and benefits of inheritance Base class and derived class objects Base class and derived class.
Final and Abstract Classes
1 Inheritance Classes and Subclasses Or Extending a Class.
CLASS INHERITANCE Class inheritance is about inheriting/deriving properties from another class. When inheriting a class you are inheriting the attributes.
Inheritance (2).
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
Inheritance zThe mechanism by which one class can inherit the properties of another. zIt allows a hierarchy of classes to be built, moving from the most.
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.
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 In C++  Inheritance is a mechanism for building class types from other class types defining new class types to be a –specialization –augmentation.
Inheritance Inheritance is the capability of one class of things to inherit the capabilities or properties from another class. Consider the example of.
INHERITANCE By: Er. Gurpreet Singh Assistant Professor Department of Information Technology, Department of Information Technology, MIMIT Malout 1.
Intro to OOP with Java, C. Thomas Wu Inheritance and Polymorphism
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 Spring 2007 – Recitation 41 Object Oriented Programming Spring 2007 Recitation 4.
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
Inheritance: Extending classes Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्जेण्डर )PGT(CS) KV JHAGRAKHAND.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 28P. 1Winter Quarter Inheritance and Overloading.
Chapter 10: Inheritance 1. Inheritance  Inheritance allows a software developer to derive a new class from an existing one  The existing class is called.
Looking toward C++ Object-Oriented Programming Traditional Programming Procedure-Oriented Programming Task-Based Programming circle method draw data C.draw()
JAVA WORKSHOP SESSION – 3 PRESENTED BY JAYA RAO MTech(CSE) NEWTON’S INSTITUTE OF ENGINEERING 1.
INHERITANCE IN C++ Amit Saxena PGT(CS) KV Rangapahar Cantt. (Nagaland)
CS212: Object Oriented Analysis and Design Lecture 14: Reusing classes in C++
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.
CSC241 Object-Oriented Programming (OOP) Lecture No. 4.
Computer Programming & Applications Mohamed Iqbal Pallipurath Lecture 02P. 1 Inheritance and Overloading Lecture 28.
XII CBSE Previous Year Question Paper QUESTION NO 2 (d) 4 Marks.
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.
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 07 classes 1 BY ADEEL ANJUM ( MSc - cs, CCNA, WEB DEVELOPER )
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني 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.
Java Inheritance in Java. Inheritance Inheritance is a mechanism in which one object acquires all the properties and behaviors of parent object. The idea.
1.  Inheritance Inheritance  Define a Class Hierarchy Define a Class Hierarchy  Visibility Mode Visibility Mode  Access Rights of Derived Classes.
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.
CS1201: Programming Language 2 Classes and objects Inheritance Nouf Aljaffan Edited by : Nouf Almunyif.
OBJECT ORIENTED PROGRAMMING WITH C++ Team Members: Lalitha.V.P(Team Head) Manonmani.S Pavithra.H.
Modern Programming Tools And Techniques-I
CS212: Object Oriented Analysis and Design
Inheritance Saras M. Srivastava LEARN BY EXAMPLES PGT – Comp. Sc.
Inheritance.
Inheritance Concept of Inheritance . Types of Inheritance .
Presented By: Nazia Hossain Lecturer, Stamford University
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Object Oriented Analysis and Design
Object Oriented Programming Language (OOP)
CS1201: Programming Language 2
Introduction Types Syntax Visibility Modes Example Programs
CS1201: Programming Language 2
CS1201: Programming Language 2
By Muhammad Waris Zargar
C++ Inheritance.
Object oriented programming (OOP) Lecture No. 7
Inheritance:Concept of Re-usability
Function Overloading.
Institute of Petroloeum Technology, Gandhinagar
B.FathimaMary Dept. of Commerce CA SJC Trichy-02
Final and Abstract Classes
Inheritance in c++ Introduction
Computer Science II for Majors
Presentation transcript:

Inheritance - Multilevel MEENA RAWAT PGT (COMP) KV ONGC Chandkheda 1

Contents 1.Objectives 2.Concept of Inheritance – Need, Example 3.Type of Class 4.Type of Inheritance - forms 5.Single level Inheritance 6.Visibility Modes 7.Multi level Inheritance 2

Objectives In this session, you will learn: – To be able to create new classes by inheriting from existing classes. – To understand how inheritance promotes software reusability. – To understand the notions of base classes and derived classes. – Forms of Inheritance 3

Concept of Inheritance - Need The mechanism by which one class can inherit the properties of another class. It allows a hierarchy of classes to be built, moving from the most general to the most specific. Code reusability - one class can be used without redefining or rewrite. It makes faster development time, easier to maintenance, easy to extend. Capability to express the inheritance relationship Transitive nature of nature 4

Real Life Examples 5

VehiclesAutomobilesCarsBike Non Auto Mobile Cycle 6

Type of Class Base Class / Super Class – Defines all qualities attributes common to any derived classes. Derived Class / Sub Class – Inherits those general properties and adds new properties that are specific to that class. 7

Different forms of Inheritance 1.Single Inheritance – one base class, one derived class 2.Multiple Inheritance – multiple base class, One derived class 3.Hierarchical Inheritance - One base class, multiple derived class 4.Multilevel Inhetitance – derived from derived class 5.Hybrid Inheritance – mixture of above 8

Single Level Inheritance One Base Class one derived class Syntax: Class derived_class_name : visibility_mode base_class_name { class members }; basederived 9

Example of Single Level Inheritance class base // base class { int x; public: void setx(int n) { x = n; } void showx() { cout << x << ‘\n’ } }; // Inherit as public class derived : public base //derived class { int y; public: void sety(int n) { y = n; } void showy() { cout << y << ‘\n’;} }; int main() { derived ob; ob.setx(10); ob.sety(20); ob.showx(); ob.showy(); } 10

Visibilit modes 1.Specified whether the features of the base class are privately or publically or protected derived. 2.Control the access-specifier to be for inheritable members of base class in the derived class. 11

Role of visibility modes Visibility Mode isInheritable public member becomes (in derived class) Inheritable protected member becomes (in derived class) Private member of base class are not directly accessible to derived class Public Protected Privateprivate 12

Public Visibility Mode X check()private Y display()public Z getval()protected 13 A init()Private Y display() B readit() Public Z getval() C writeval() Protected Class Super Class Base

Private Visibility Mode X check()private Y display()public Z getval()protected 14 A init() Y display() Z getval() Private B readit()Public C writeval()Protected Class Super Class Base

Protected Visibility Mode X check()private Y display()public Z getval()protected 15 A init()Private B readit()Public C writeval() Y display() Z getval() Protected Class Super Class Base

Multilevel Inheritance (derived from a derived class) 16

Example #include class mm { protected: int rollno; public: void get_num(int a) { rollno = a; } void put_num() { cout << "Roll Number Is:\n"<< rollno << "\n"; } }; class marks : public mm { protected: int sub1; int sub2; public: void get_marks(int x,int y) { sub1 = x; sub2 = y; } void put_marks(void) { cout << "Subject 1:" << sub1 << "\n"; cout << "Subject 2:" << sub2 << "\n"; } }; 17

class res : public marks { protected: float tot; public: void disp(void) { tot = sub1+sub2; put_num(); put_marks(); cout << "Total:"<< tot; } }; int main() { res std1; std1.get_num(5); std1.get_marks(10,20); std1.disp(); return 0; } 18

Multiple Inheritance – many base class, one derived class Syntax: Class derived_class_name : visibility_mode base_class_name, visibility_mode base_class_name { class members }; 19

Question asked in Board Exam Answer the questions (i) to (iv) based on the following: 4 class PUBLISHER { char Pub[12]; double Turnover; protected: void Register(); public: PUBLISHER(); void Enter(); void Display(); }; class BRANCH { char CITY[20]; protected: float Employees; public: BRANCH(); void Haveit(); void Giveit(); }; class AUTHOR:private BRANCH,public PUBLISHER { int Acode; char Aname[20]; float Amount; public: AUTHOR(); void Start(); void Show(); }; Write the names of data members, which are accessible from objects belonging to class AUTHOR. Write the names of all the member functions which are accessible from objects belonging to class BRANCH. Write the names of all the members which are accessible from member functions of class AUTHOR. How many bytes will be required by an object belonging to class AUTHOR? 20

Thank You. 21