1 / 23

Need for Inheritance

Need for Inheritance. Capability of inheriting features. Transitive relationship. Reusablity of class. Computer Science -083. Presented By Lakshmi Kumari K.V. Shaktinagar. Content. Introduction Different forms of inheritance Visibility mode Accessibility of base class member

samira
Download Presentation

Need for Inheritance

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.

  2. Computer Science -083 Presented By Lakshmi Kumari K.V. Shaktinagar

  3. Content • Introduction • Different forms of inheritance • Visibility mode • Accessibility of base class member • Assignment

  4. INHERITANCE The mechanism of deriving a new class from an old one is called Inheritance.

  5. Example Base Class Father Existing class is called Base Class. Raj Rani Roshan Derived Class New class is called derived class.

  6. DIFFERENT FORMS OF INHERITANCE INHERITANCE SINGLE INHERITANCE MULTIPLE INHERITANCE MULTILEVEL INHERITANCE HIERARCHICAL INHERITANCE HYBRID INHERITANCE

  7. Single Inheritance When a subclass inherit only from one base class,it is known as single inheritance. Super Class (Base Class) Super Class Sub Class (Derived Class) Derived Class

  8. Colon gives that derived class-name is derived from base-class. Syntax: Class Derived-class : Mode base-class { St1; St2; }; Mode is either private or public.By default mode is private

  9. Base Class & Derived Class The new class is called Derived Class and old one is called Base class. Class Student { Public: int Roll; }; Class Ipstudent : public Student { Private : int ipmarks; Public : void info( ) { cout<< Roll; cout<<ipmarks; } }; Main( ) { ipstudent ip; ip.Roll=1; Ip.info( ); }

  10. Hierarchical Inheritance Father Daughter son When many subclasses inherit from a single base class ,it is known as hierarchical inheritance.

  11. Name of different base class Syntax: Class Derived-class : Mode base-class1,Mode base-class2 { St1; St2; }; Mode is either private or public.By default mode is private

  12. MULTI LEVEL INHERITANCE Super Class Sub Class 1 Sub Class 2 When a subclass inherits from a class that itself inherits from another class it is known as multilevel inheritance.Slide 6

  13. Multiple Inheritance Father Mother son When one subclass inheriting from many base class ,it is known as hierarchical inheritance.Syntax:

  14. Hybrid Inheritance Father son Daughter in law son of Abhi & Aish When a subclass inherits from multiple base classes and all of its base classes inherit from a single base class,this form of inheritance is known as hybrid inheritance..

  15. Visibility Mode • Private When base class is privately accessed by derived class then • Public member Private • Protected member Private • Private member Not inherited Base Class Derived Class become

  16. Visibility Mode • Public When base class is publicly accessed by derived class then • Private member Not inherited • Public member Public • Protected member Protected Base Class Derived Class

  17. Visibility Mode • Protected When base class is accessed protectly by derived class then • Private member Not inherited • Public member Protected • Protected member Protected Base Class Derived Class

  18. The significance of visibility modes • Private :-When the derived class require to use some attributes of the base class and these inherited features are intended not to be inherited further . • Public :-When the situation wants the derived class to have all the attributes of the base class,plus some extra attributes. • Protected:- When the features are required to be hidden from the outside world and at same time required to be inheritable.

  19. Accessibility of base class member

  20. Assignment • What is inheritance? • How many type of inheritance? • When should one derive a class publicly or privately?

  21. 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:privateBRANCH,public PUBLISHER{intAcode;char Aname[20]; float Amount;public: AUTHOR(); void Start(); void Show();};1.Write the names of data members, which are accessible from objects belonging to class AUTHOR.2.Write the names of all the member functions which are accessible from objects belonging to class BRANCH.3. Write the names of all the members which are accessible from member functions of class AUTHOR.4 How many bytes will be required by an object belonging to class AUTHOR?

  22. May you all prosper and be happy! With a lot of love and respectThank You all

More Related