Your SlideShare is downloading. ×
0
Inheritance
Inheritance
Inheritance
Inheritance
Inheritance
Inheritance
Inheritance
Inheritance
Inheritance
Inheritance
Inheritance
Inheritance
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Inheritance

578

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
578
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
28
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Inheritance Anurag Pramod Daware TE H 22
  • 2. Inheritance• One of the Major pillars of OOP approach.• Process by which one object acquires properties of another.• New classes to be built from older one.• ‘IS A’ relationship• Ex: Parent Parent Features Base Class Parent Features Child Child Derived Class Features
  • 3. Inheritance• Allows Hierarchical Classification of Objects.
  • 4. Benefits• Reusable code, reliability and decreased maintenance cost.• Code Sharing: software level and class level• Extension: Construction of new system from old components: focus on new and unusual parts of system
  • 5. Types of Inheritance in C++ A A B C D B (D) Hierarchical(a) Single A B A A C B (C) Multiple B C C D(b) Multilevel (E) Hybrid
  • 6. Syntaxclass derived-class-name : visibility modebase class-name{ ...// ...// members of derived class ...//};egg.Class ABC : private XYZ{ members of ABC};
  • 7. Visibility ModesBase Class Derived Class Derived Class Visibility: Visibility:Visibility Public Private Derivation Derivationprivate Not inherited Not inheritedprotected protected privatepublic public private
  • 8. A Exampleclass B //base class{ protected: int x; int y; public: B() { } //default constructor void read() { cout<<“ Enter X of Class B :”; cin>>x; cout<<“ Enter Y of Class B :”; cin>>y; } void show() { cout<<“ X in class B:” << x <<endl; cout<<“ y in class B:” << y <<endl;
  • 9. class D: public B //derived class{ protected: int y, int z; public: D() { } //default constructor void read() { B :: read(); //read base class data first cout<<“ Enter Y of Class D :”; cin>>y; cout<<“ Enter Z of Class D :”; cin>>z; } void show() { B :: show(); //display base class data cout<<“ X in class B:” << x <<endl; cout<<“ y in class B:” << y <<endl;
  • 10. void main(){ D d; //obj of derived cout<< “Enter data for object of class D ..” <<endl; d.read(); cout<< “Contents of object of class D ..” <<endl; d.show(); }--------------------------------------------------------------if input given is 1 2 3 4 op will beContents of object of class D ..X in class B : 1Y in class B : 2Y in class D : 3Z in class D : 4Y of B, show from D = 2
  • 11. Virtual InheritanceProblems with Multiple Inheritance:1.Ambiguos Function call2.Duplication of Data MembersSolutionUse virtual keywordclass A {};class B: virtual public A{};class C: virtual public A{};Class D: public B, public C {};
  • 12. Thank You..

×