Inheritance:Concept of Re-usability

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.
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 BASICS Reusability is achieved by INHERITANCE
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.
CSE 1302 Lecture 8 Inheritance Richard Gesick Figures from Deitel, “Visual C#”, Pearson.
C++ Inheritance Gordon College CPS212. Basics OO-programming can be defined as a combination of Abstract Data Types (ADTs) with Inheritance and Dynamic.
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.
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 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.
Inheritance. Types of Inheritance Implementation inheritance means that a type derives from a base type, taking all the base type’s member fields and.
Inheritance using Java
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
CS212: Object Oriented Analysis and Design Lecture 15: Inheritance in C++ -II.
INHERITANCE IN C++ Amit Saxena PGT(CS) KV Rangapahar Cantt. (Nagaland)
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.
Session 04 Module 8: Abstract classes and Interface Module 9: Properties and Indexers.
Inheritance, Polymorphism, And Virtual Functions Chapter 15.
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.
 A constructor is a special member function whose task is to initialize the objects of its class.  It is special because its name is same as the class.
INHERITANCE : Extending Classes. Rickshaw cart Bus Car Pulled Vehicles Inheritance Inheritance Vehicles Inheritance is the capability of one class of.
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.
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.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
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.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
OBJECT ORIENTED PROGRAMMING WITH C++ Team Members: Lalitha.V.P(Team Head) Manonmani.S Pavithra.H.
Classes (Part 1) Lecture 3
2 Chapter Classes & Objects.
Inheritance Concept of Inheritance . Types of Inheritance .
Objects as a programming concept
2.7 Inheritance Types of inheritance
Inheritance AKEEL AHMED.
Inheritance in Java.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Week 8 Lecture -3 Inheritance and Polymorphism
Object Oriented Programming Language (OOP)
Ambiguity Resolution in Inheritance
Contents Introduction to Constructor Characteristics of Constructor
HYBRID INHERITANCE : AMBIGUITY REMOVAL
Inheritance Dr. Bhargavi Goswami Department of Computer Science
Inheritance, Polymorphism, and Virtual Functions
Inheritance and Polymorphism:
Introduction Types Syntax Visibility Modes Example Programs
INHERITANCE BASICS Reusability is achieved by INHERITANCE
By Muhammad Waris Zargar
Inheritance Cse 3rd year.
Adapter Design Pattern
Institute of Petroloeum Technology, Gandhinagar
B.FathimaMary Dept. of Commerce CA SJC Trichy-02
Object Oriented Programming
ENERGY 211 / CME 211 Lecture 22 November 10, 2008.
Inheritance in c++ Introduction
Inheritance in C++ Inheritance Protected Section
Programming in C# CHAPTER 5 & 6
Computer Science II for Majors
Presentation transcript:

Inheritance:Concept of Re-usability Chapter 4 Inheritance:Concept of Re-usability

What is Inheritance Inheritance is the capability of one class to acquire properties and characteristics from another class. The mechanism of deriving a new class from an old one is called inheritance (or derivation) Old class whose properties are inherited by other class is called the Parent or Base or Super class. New class class who inherits property of other class is called the Parent or Base or Super class.

The derived class can inherits some or all traits from the base class. A class can also inherit properties from more than one class. Types of inheritance Single inheritance Multiple inheritance Multilevel inheritance Hierarchical inheritance Hybrid inheritance

Single Inheritance: In this type of inheritance one derived class inherits from only one base class. It is the most simplest form of Inheritance.

Multiple Inheritance In this type of inheritance a single derived class may inherited from two or more than two base classes. Base class Derived Class

Multilevel Inheritance In the type of inheritance in which derived class get derived from another derived class. Base class Base for C and derive Class for A derive class of B

Hierarchical Inheritance In this type of inheritance, multiple derived classes inherits from a single base class. Base class derive classes

Hybrid (Virtual) Inheritance: Hybrid Inheritance is combination of Hierarchical and Multilevel Inheritance.

Defining Derived Classes Syntax: Class derived_class name : visibility-mode base_class name { member of derived class; member function of derived class; }; Example: class ABC : Public XYZ int a,b; void getdata ( ); }

The colon indicates that the derived_class name is derived from base_class name The visibility mode is optional if it is present my be either private or public. The default visibility mode is private. Visibility mode specifies that whether the features of the base class are privately derived or publicly derived.

Base class can be inherited in following ways: Privately inheritance Publicly inheritance No private data members can be inherited in any of the above method. Only public data members of base class can be inherited.

When base class is privately inherited by derived class all data members and member function (public/Private) are become private data of derived class. As we have seen that all member function should declared as public because we are going to access it in main() function using object of class In this case we are deriving it privately automatically all member function get private which are not accessible by object of derived class.

When the base class is publicly inherited the 'public members' of the base class become 'public members' of the derived class. They are accessible to the objects of the derived class.

Derived class Base class

If the class inherited as Public

The program shows that the object of class D have access to all public members of class B.s a is a private in class B & can’t be inherited by D Although the data member ‘a’ is private & can’t be inherited, object of D are able to access it by an inherited functions of class B

The program shows that the object of class D have access to all public members of class B.s a is a private in class B & can’t be inherited by D Although the data member ‘a’ is private & can’t be inherited, object of D are able to access it by an inherited functions of class B

If the class is inherited Privately

In private derivation, the public memebers of the base class become private memebers of the derived class. The object of D can’t access to the public member of B Such as d.get_ab(); d.get_a(); d.show_a(); We can access this private member function by calling them into a public member function of a class

Accessing private function by calling them into public functions of class

We can access private data members of base class in derived class by making them as public. Another way is that c++ provides third visibility modifier PROTECTED A member declared as protected is accessible by member of the same class and any immediately derived class

Virtual Base class