Inheritance
I nheritance  is a mechanism of reusing and extending existing classes without modifying them, thus producing hierarchical...
<ul><li>V isibility  M odifier :  </li></ul>P rivate :   A member declared as private is accessible by the member function...
<ul><li>D efining  D erived  C lass   </li></ul>Class derived_class_name : visibility mode base_class_name  { …  // member...
<ul><li>T ypes  of I nheritance :   </li></ul>Single Inheritance  Class A {….};  Class B : public A {----};  Class A {…}; ...
<ul><li>T ypes  of I nheritance :   </li></ul>Multiple Inheritance  Hierarchical Inheritance   Class A {…}; Class B {…}; C...
Hybrid Inheritance  Class A {…}; Class B : public A {…}; Class C : public B {…}; Class D : public C {…}; A B C D
V isibility  M ode: <ul><li>When the base class is privately inherited by the derived class,’public members of the base cl...
V irtual  B ase  C lass   A B C D Here, D will have duplicate sets of members inherited from A I.e, via B  and C  Duplicat...
Class A  {-----};   Class B : virtual public A  {------};   Class C : public virtual A  {------};   Class D : public B, pu...
Thank you
Upcoming SlideShare
Loading in …5
×

inheritence

1,493 views

Published on

a.b

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

  • Be the first to like this

No Downloads
Views
Total views
1,493
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

inheritence

  1. 1. Inheritance
  2. 2. I nheritance is a mechanism of reusing and extending existing classes without modifying them, thus producing hierarchical relationship between them. BASE CLASS DERIVED CLASS ADVANTAGES: <ul><li>R eusability </li></ul><ul><li>E xtendibility </li></ul><ul><li>E asy debugging </li></ul>
  3. 3. <ul><li>V isibility M odifier : </li></ul>P rivate : A member declared as private is accessible by the member functions of its class only. P ublic : A member declared as public is accessible by the member functions within its class and any class that derives it. P rivate : A member declared as protected is accessible by the member functions within its class and any class immediately derived from it.
  4. 4. <ul><li>D efining D erived C lass </li></ul>Class derived_class_name : visibility mode base_class_name { … // members of derived class }; Eg: Class ABC : public XYZ {…};
  5. 5. <ul><li>T ypes of I nheritance : </li></ul>Single Inheritance Class A {….}; Class B : public A {----}; Class A {…}; Class B:public A {…}; Class C: public B {…}; Multilevel Inheritance A B A B C
  6. 6. <ul><li>T ypes of I nheritance : </li></ul>Multiple Inheritance Hierarchical Inheritance Class A {…}; Class B {…}; Class C: public A, public B {…}; Class A {…}; Class B : public A {…}; Class C : public B {…}; Class D : public C {…}; A B C A B C D
  7. 7. Hybrid Inheritance Class A {…}; Class B : public A {…}; Class C : public B {…}; Class D : public C {…}; A B C D
  8. 8. V isibility M ode: <ul><li>When the base class is privately inherited by the derived class,’public members of the base class becomes ‘private members’ of the derived class. </li></ul><ul><li>When the base class is publicly inherited,’public members’ of the base class become ‘public members’ of the derived class. </li></ul><ul><li>When a base class is derived in protected mode,both the public and protected members of the class become protected members of the derived class. </li></ul>
  9. 9. V irtual B ase C lass A B C D Here, D will have duplicate sets of members inherited from A I.e, via B and C Duplicate ambiguity can be avoided by making The common base class as virtual class
  10. 10. Class A {-----}; Class B : virtual public A {------}; Class C : public virtual A {------}; Class D : public B, public C {------}; When a class is made virtual base class, C++ takes necessary care to see that only one copy of that class is inherited, regardless of how many inheritance paths exist between the virtual base class and a derived class.
  11. 11. Thank you

×