By Muhammad Waris Zargar

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

CLASS INHERITANCE Class inheritance is about inheriting/deriving properties from another class. When inheriting a class you are inheriting the attributes.
Chapter 14 Inheritance Pages ( ) 1. Inheritance: ☼ Inheritance and composition are meaningful ways to relate two or more classes. ☼ Inheritance.
Constructor. 2 constructor The main use of constructors is to initialize objects. A constructor is a special member function, whose name is same as class.
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
I NHERITANCE Chapter 7 Department of CSE, BUET 1.
Inheritance. Many objects have a hierarchical relationship –Examples: zoo, car/vehicle, card game, airline reservation system Inheritance allows software.
Chapter 1 Inheritance University Of Ha’il.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
Derived Classes. C++ 2 Outline  Definition  Virtual functions  Virtual base classes  Abstract classes. Pure virtual functions.
C++ Classes & Data Abstraction
LOGO Lecturer: Abdullahi Salad Abdi May 1, Object Oriented Programming in C++
Inheritance Definition Relationships Member Access Control Data Encapsulation Overloading vs. Overriding Constructors & Destructors.
Inheritance Concept of Inheritance (What, Why, and How) Simple Example of Inheritance Base Classes and Derived Classes Private Member Data vs. Protected.
Learners Support Publications Inheritance: Extending Classes.
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
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.
CS-2135 Object Oriented Programming
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
Inheritance: Extending classes Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्जेण्डर )PGT(CS) KV JHAGRAKHAND.
Object Oriented Programming using VC++. Introduction Program – Set of instruction written in a high level language High level language used for writing.
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Taken from slides of Starting Out with C++ Early Objects Seventh Edition.
Chapter 11: Inheritance and Composition. Objectives In this chapter, you will: – Learn about inheritance – Learn about derived and base classes – Redefine.
Inheritance Inheritance – most important and a useful feature of OOPs supported by C++ | Website for Students | VTU -NOTES -Question Papers.
Inheritance Session 5 Object Oriented Programming with C++/ Session 5/ 1 of 41.
CS212: Object Oriented Analysis and Design Lecture 15: Inheritance in C++ -II.
INHERITANCE IN C++ Amit Saxena PGT(CS) KV Rangapahar Cantt. (Nagaland)
Data Structures Using C++ 2E1 Inheritance An “is-a” relationship –Example: “every employee is a person” Allows new class creation from existing classes.
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
Inheritance: Base and Derived Classes. Introduction In dictionary inheritance is defined as the action of inheriting; the transfer of property; to receive.
Constructor in Inheritance. 2 Constructors are used to initialized object. In inheritance the base class contains default constructor then, the base class.
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.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
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.
Object-Oriented Programming (OOP) What we did was: (Procedural Programming) a logical procedure that takes input data, processes it, and produces output.
A class may de defined to automatically include the data members and member functions of an already existing class. New data members and member functions.
Chapter 11: Inheritance and Composition. Introduction Two common ways to relate two classes in a meaningful way are: – Inheritance (“is-a” relationship)
Inheritance in C++ Bryce Boe 2012/08/28 CS32, Summer 2012 B.
CPS120: Introduction to Computer Science Lecture 16A Object-Oriented Concepts.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Modern Programming Tools And Techniques-I
Lecture 12 Inheritance.
Today’s Objectives 5-Jul-2006 Announcements
By Muhammad Waris Zargar
Inheritance Concept of Inheritance . Types of Inheritance .
2.7 Inheritance Types of inheritance
Class A { public : Int x; A()
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Polymorphism Lec
Object Oriented Analysis and Design
Ambiguity Resolution in Inheritance
Class Inheritance (Cont.)
Learning Objectives Inheritance Virtual Function.
HYBRID INHERITANCE : AMBIGUITY REMOVAL
Virtual Functions Department of CSE, BUET Chapter 10.
Inheritance Dr. Bhargavi Goswami Department of Computer Science
Inherited Classes in Java
Interfaces.
Java Programming, Second Edition
C++ Inheritance.
Inheritance:Concept of Re-usability
Chapter 11: Inheritance and Composition
Inheritance and Polymorphism
Eighth step for Learning C++ Programming
C++ Programming CLASS This pointer Static Class Friend Class
Inheritance in C++ Inheritance Protected Section
Presentation transcript:

By Muhammad Waris Zargar inheritance By Muhammad Waris Zargar

Inheritance Introduction Advantages Categories of inheritance Specifying A derive class syntax: class derive class name: access specifier parent class;

Specifying A Derive Class Accessing Members Of Parent Class Accessing Constructor Of Parent Class Accessing Member Function Of Parent Class Function Overriding Types Of Inheritance Public Inheritance Protected Inheritance Private Inheritance Multi Level Inheritance

Multi Level Inheritance with parameter Multiple Inheritance Constructor In Multiple Inheritance Constructor without parameter Constructor with parameter Ambiguity In Multiple Inheritance Removing Ambiguity Containership

Introduction Person Reuse an existence class. New class inherit all behavior of original class. It has also some additional properties. The existing class is called super , parent , base class. New class is called derived , base , child. Example: Person Student Teacher Labour

Advantages Reusability. Save time and effort. Increase program structure and reliability.

Categories Parent Parent1 Parent2 Child Child Single inheritance Multiple Inheritance Parent Parent1 Parent2 Child Child

Access Specifier Access Specifier Main Class Derive Class Main Function Private Yes No Protected Public

Accessing Members Of Parent Class Important point is accessing member of parent class using derive class object. class waris{ public: Int num; }; Class haris : public waris{}; Int main(){ Haris h; h.num=20; Cout << “ Number is : : “ << h.num; }

Accessing Constructor Of Parent Class Important point is accessing member of parent class using derive class object. class waris{ public: Int main(){ Waris(){cout <<“I am in parent class”;} Haris h; } }; Class haris : public waris{ Haris() : waris(){ Cout <<“I am derive class constructor”;

Accessing Constructor Of Parent Class Important point is accessing member of parent class using derive class object. class waris{ public: Int main(){ Waris(int a){cout <<“I am in parent class”;} Haris h(2,3); } }; Class haris : public waris{ Haris(int a , int b) : waris(b){ Cout <<“I am derive class constructor”; } }

Accessing Member function Of Parent Class Important point is accessing member of parent class using derive class object. Class waris{ Void input(); void show(); void tell(); }; Class haris : public waris{ Void squre(); Int main(){ Haris obj; Obj.input(); obj.show(); obj.tell(); Obj.squre(); }

Function Overriding Method: The process of declaring member function in derive with same name as in the parent name is called function overriding. The object of derive class cannot access the member function of parent class. Method: Scope Resolution operator(In the function of derive class). Base pointer. Non member function In the main function i.e (derive object . Parent class name :: function name);

Type of inheritance Public Inheritance. Private Inheritance. Protected Inheritance.

Public Inheritance In Derive Class In Main Body Public Public The derive class can access the member. The derive class can access the member. The derive class cannot access the member. The derive class object can access the member. The derive class object cannot access the member. Public Protected Private In Main Body Public Protected Private

Protected Inheritance In Derive Class The derive class can access the member. The derive class can access the member. The derive class cannot access the member. The derive class object cannot access the member. The derive class object cannot access the member. Public Protected Private In Main Body Public Protected Private

Private Inheritance In Derive Class In Main Body Public Public The derive class can access the member. The derive class can access the member. The derive class cannot access the member. The derive class object cannot access the member. The derive class object cannot access the member. Public Protected Private In Main Body Public Protected Private

Multilevel Inheritance A type of inheritance in which a derive class is derive from an other class. Syntax: Class A{ body of class}; Class B : public A {body of class }; Class C : public B {body of class }; Use of function overriding method Void fun(){ A :: fun2; B :: fun3; }

Multi level inheritance with parameter Class A{ Void in1(int a){} }; Class B : public A{ Void in(int a ,int b){ A : : in1(a); } Class c : public B{ Void in3(int a , int , b , int c){ B :: in(a , b);

Multiple Inheritance Class A Class B Class C If a derive class has more than one parent class is called multiple inheritance. Class B Class A Class C

Constructor And Destructor First Parent class constructor called. Second Derive class constructor is called. First derive class destructor called. Second parent class destructor called.

Ambiguity In Inheritance Call the function in derive class using scope resolution operator . { A : : function name() } Call in main function using derive class on object. Object .parent class name :: function();

ContainerShip Example: Relate The classes. To call the function of one class into other class using object of class. Example: Class Waris { void in() ; void show() ; void tell() ; }; class Haris { Waris object ; Void show(){ Object.in(); object.show(); object.tell(); } };