1.  Inheritance Inheritance  Define a Class Hierarchy Define a Class Hierarchy  Visibility Mode Visibility Mode  Access Rights of Derived Classes.

Slides:



Advertisements
Similar presentations
2006 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Inheritance.
Advertisements

Chapter 5 Inheritance. Objectives Introduction, effects, and benefits of inheritance Base class and derived class objects Base class and derived class.
Chapter 14 Inheritance Pages ( ) 1. Inheritance: ☼ Inheritance and composition are meaningful ways to relate two or more classes. ☼ Inheritance.
I NHERITANCE Chapter 7 Department of CSE, BUET 1.
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++
Copyright 2006 Oxford Consulting, Ltd1 February C++ Inheritance Data Abstraction and Abstract Data Types Abstract Data Type Encapsulated data.
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.
1 class Rectangle{ private: int numVertices; float *xCoord, *yCoord; public: void set(float *x, float *y, int nV); float area(); }; Inheritance Concept.
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.
Learners Support Publications Inheritance: Extending Classes.
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
You gotta be cool. Inheritance Base Classes and Derived Classes Inheritance: Public, Protected, Private What is inherited from the base class? Multiple.
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
תכנות מונחה עצמים Object Oriented Programming (OOP) אתגר מחזור ב' Inheritence ( הורשה Inheritence ( הורשה ( השקפים מבוססים על שקפים של אליהו ברוטמן ומרינה.
Data Structures Using C++1 Chapter 2 Object-Oriented Design (OOD) and C++
Chapter 12: Adding Functionality to Your Classes.
1 What is Inheritance? zThe mechanism of deriving a new class from an old one is called inheritance zClasses organised into a ‘classification hierarchy’
CSCI-383 Object-Oriented Programming & Design Lecture 14.
Inheritance Session 5 Object Oriented Programming with C++/ Session 5/ 1 of 41.
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.
CS212: Object Oriented Analysis and Design Lecture 14: Reusing classes in C++
Chapter 10 Inheritance and Polymorphism
Copyright 2006 Oxford Consulting, Ltd1 February Polymorphism Polymorphism Polymorphism is a major strength of an object centered paradigm Same.
Inheritance - Multilevel MEENA RAWAT PGT (COMP) KV ONGC Chandkheda 1.
Computer Science Department CPS 235 Object Oriented Programming Paradigm Lecturer Aisha Khalid Khan Inheritance.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Object Oriented Programming COP3330 / CGS5409.  Inheritance  Assignment 5.
INHERITANCE : Extending Classes. Rickshaw cart Bus Car Pulled Vehicles Inheritance Inheritance Vehicles Inheritance is the capability of one class of.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Inheritance.
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.
Department of Computer Science Data Structures Using C++ 2E Chapter 2 Object-Oriented Design (OOD) and C++  Learn about inheritance  Learn about derived.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Introduction to Object Oriented Programming (OOP) Object Oriented programming is method of programming.
CS1201: Programming Language 2 Classes and objects Inheritance By: Nouf Aljaffan Edited by : Nouf Almunyif.
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.
CITA 342 Section 1 Object Oriented Programming (OOP)
Package A package is a logical container that contains classes,interfaces sub packages. Package provide a unique name space to its members and provide.
Classes, Interfaces and Packages
1 Another way to define a class Inheritance..!!. 2 Why Inheritance ? Inheritance is a mechanism for building class types from existing class types defining.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Object Oriented Programming(Objects& Class) Classes are an expanded concept of data structures: like.
1 Chapter 4: Another way to define a class Inheritance..!!
1 Object-Oriented Programming Inheritance. 2 Superclasses and Subclasses Superclasses and Subclasses  Superclasses and subclasses Object of one class.
CSC241 Object-Oriented Programming (OOP) Lecture No. 14.
Class & Objects C++ offers another user-defined data type known class which is the most important feature of the object-oriented programming. A class can.
MAITRAYEE MUKERJI Object Oriented Programming in C++: Hierarchy / Inheritance.
CS1201: Programming Language 2 Classes and objects Inheritance Nouf Aljaffan Edited by : Nouf Almunyif.
1 Inheritance One of the goals of object oriented programming is code reuse. Inheritance is one mechanism for accomplishing code reuse. It allows us to.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
Chapter 2 Objects and Classes
Inheritance Concept Polygon Rectangle Triangle class Rectangle{
Inheritance Basics Fall 2008
PHP Classes and Objects
Packages, Interfaces & Exception Handling
Inheritance Dr. Bhargavi Goswami Department of Computer Science
CLASSES AND OBJECTS.
Object oriented programming (OOP) Lecture No. 7
Inheritance:Concept of Re-usability
NAME 436.
Unit-2 Objects and Classes
COP 3330 Object-oriented Programming in C++
Another way to define a class
ENERGY 211 / CME 211 Lecture 22 November 10, 2008.
Inheritance in C++ Inheritance Protected Section
Computer Science II for Majors
Presentation transcript:

1

 Inheritance Inheritance  Define a Class Hierarchy Define a Class Hierarchy  Visibility Mode Visibility Mode  Access Rights of Derived Classes Access Rights of Derived Classes  Access Control to different Members of a Class Access Control to different Members of a Class

 Inheritance is a mechanism of deriving a new class(derived class) from an old one(base class).  For example,an organization consists of various types of employees like managers,engineers,technicians and so on.In this case,employee is the base class and engineer is the derived class. 3

4 Putting Them Together  Employee is the base class  Engineer is the derived class  The derived class can ◦ inherit all members from the base class, except the constructor ◦ access all public and protected members of the base class ◦ define its private data member ◦ provide its own constructor ◦ define its public member functions EngineerEmployee BACK

5  Syntax: class DerivedClassName : visibility-mode BaseClassName { ………; // members of derived class ………; } The Colon Symbol(: ) shows the relationship of a derived class to its base class where ◦ Visibility-mode specifies the type of derivation  private by default, or public  Any class can serve as a base class ◦ Thus a derived class can also be a base class BACK

When visibility mode is Private  Then public members of a base class will be considered as private menbers of the derived class  Then all public members of a base class will be considered as public menbers of the derived class 6 When visibility mode is Public

7  The private members of the base class can not be inherited and it is not available for the derived class.  One way to solve this problem is by changing the visibility mode of the private member by making it public.  When a member declared as Protected is accesible by the member functions within the class and any class immediately derived from it.

8 class class_name { private: … //By default … //visible to member functions … of its own protected: … //visible to member functions … of its own and derived class … public: … // visible to all … }; BACK

9  The type of inheritance defines the access level for the members of derived class that are inherited from the base class Access Specifier Private Derivation Protected Derivation Public Derivation private Not Inherited protectedprivateprotected publicprivateprotectedpublic Type of Inheritance Access Controlfor Members BACK

10 Access Specifier Accessible from own class Accessible from derived class Accesssible from Objects Outside Class PublicYes ProtectedYes No PrivateYesNo BACK

11