SlideShare a Scribd company logo
1 of 15
Chapter: 09


          Inheritance
                Lecture: 33
              Date: 10.10.2012
Class Hierarchies
Public and Private Inheritance
class employee         //base class
{          };

class teacher : public employee       //publicly-derived
{           };

class teacher : private employee      //privately-derived
{           };
Public and Private Inheritance
Levels of Inheritance
   Classes can be derived from classes that are themselves
    derived.
Levels of Hierarchies
Multiple Inheritance
   A class can be derived from more than one base class
Multiple Inheritance
Aggregation: Classes Within Classes
   Both inheritance and aggregation are class
    relationships.
   Inheritance is “kind of” relationship - association.
   Aggregation is “has a” relationship - association
   Def. Aggregation - Several things grouped together
                        or considered as a whole.
Aggregation: Classes Within Classes
   Both inheritance and aggregation are class
    relationships.
   Inheritance is “kind of” relationship - association.
   Aggregation is “has a” relationship - association
   Def. Aggregation - Several things grouped together
                        or considered as a whole.
Aggregation: Classes Within Classes
Aggregation may occur when one object is an attribute of another.
In other words, one class contains objects of another class.
Example:

class A
 {     };

class B
 {
    A objA;     //object of class A is an attribute of class B
 };
Aggregation: Classes Within Classes
Aggregation: Classes Within Classes
Composition: A Stronger Aggregation
   Composition is a stronger form of aggregation, having
    all its plus two more
       The part may belong to only one whole
       The lifetime of the part is the same as the lifetime of the whole
   While aggregation is a “has a” relationship, composition
    is a “consists of” relationship.
Composition: A Stronger Aggregation
   Composition is a stronger form of aggregation, having
    all its plus two more
       The part may belong to only one whole
       The lifetime of the part is the same as the lifetime of the whole
   While aggregation is a “has a” relationship, composition
    is a “consists of” relationship.

More Related Content

Similar to Lec 33 - inheritance

Object Oriented Relationships
Object Oriented RelationshipsObject Oriented Relationships
Object Oriented RelationshipsTaher Barodawala
 
lkjhlkjhjhkjhlkjhkjhkjhkjhkjhkjhjhkjh.ppt
lkjhlkjhjhkjhlkjhkjhkjhkjhkjhkjhjhkjh.pptlkjhlkjhjhkjhlkjhkjhkjhkjhkjhkjhjhkjh.ppt
lkjhlkjhjhkjhlkjhkjhkjhkjhkjhkjhjhkjh.pptEliasPetros
 
E -COMMERCE.ppt
E -COMMERCE.pptE -COMMERCE.ppt
E -COMMERCE.pptclassall
 
1- Are a private and a platoon in an encapsulation or an inheritence r.docx
1- Are a private and a platoon in an encapsulation or an inheritence r.docx1- Are a private and a platoon in an encapsulation or an inheritence r.docx
1- Are a private and a platoon in an encapsulation or an inheritence r.docxtpaula2
 

Similar to Lec 33 - inheritance (8)

Object Oriented Relationships
Object Oriented RelationshipsObject Oriented Relationships
Object Oriented Relationships
 
Association
AssociationAssociation
Association
 
Java(inheritance)
Java(inheritance)Java(inheritance)
Java(inheritance)
 
lkjhlkjhjhkjhlkjhkjhkjhkjhkjhkjhjhkjh.ppt
lkjhlkjhjhkjhlkjhkjhkjhkjhkjhkjhjhkjh.pptlkjhlkjhjhkjhlkjhkjhkjhkjhkjhkjhjhkjh.ppt
lkjhlkjhjhkjhlkjhkjhkjhkjhkjhkjhjhkjh.ppt
 
E -COMMERCE.ppt
E -COMMERCE.pptE -COMMERCE.ppt
E -COMMERCE.ppt
 
1- Are a private and a platoon in an encapsulation or an inheritence r.docx
1- Are a private and a platoon in an encapsulation or an inheritence r.docx1- Are a private and a platoon in an encapsulation or an inheritence r.docx
1- Are a private and a platoon in an encapsulation or an inheritence r.docx
 
Inheritance used in java
Inheritance used in javaInheritance used in java
Inheritance used in java
 
Inheritance
InheritanceInheritance
Inheritance
 

More from Princess Sam

Lec 49 - stream-files
Lec 49 - stream-filesLec 49 - stream-files
Lec 49 - stream-filesPrincess Sam
 
Lec 42.43 - virtual.functions
Lec 42.43 - virtual.functionsLec 42.43 - virtual.functions
Lec 42.43 - virtual.functionsPrincess Sam
 
Lec 40.41 - pointers
Lec 40.41 -  pointersLec 40.41 -  pointers
Lec 40.41 - pointersPrincess Sam
 
Lec 38.39 - pointers
Lec 38.39 -  pointersLec 38.39 -  pointers
Lec 38.39 - pointersPrincess Sam
 
Lec 47.48 - stream-files
Lec 47.48 - stream-filesLec 47.48 - stream-files
Lec 47.48 - stream-filesPrincess Sam
 
Lec 45.46- virtual.functions
Lec 45.46- virtual.functionsLec 45.46- virtual.functions
Lec 45.46- virtual.functionsPrincess Sam
 
Lec 30.31 - inheritance
Lec 30.31 -  inheritanceLec 30.31 -  inheritance
Lec 30.31 - inheritancePrincess Sam
 
Lec 28 - operator overloading
Lec 28 - operator overloadingLec 28 - operator overloading
Lec 28 - operator overloadingPrincess Sam
 
Lec 26.27-operator overloading
Lec 26.27-operator overloadingLec 26.27-operator overloading
Lec 26.27-operator overloadingPrincess Sam
 
Lec 25 - arrays-strings
Lec 25 - arrays-stringsLec 25 - arrays-strings
Lec 25 - arrays-stringsPrincess Sam
 

More from Princess Sam (13)

Lec 50
Lec 50Lec 50
Lec 50
 
Lec 49 - stream-files
Lec 49 - stream-filesLec 49 - stream-files
Lec 49 - stream-files
 
Lec 42.43 - virtual.functions
Lec 42.43 - virtual.functionsLec 42.43 - virtual.functions
Lec 42.43 - virtual.functions
 
Lec 40.41 - pointers
Lec 40.41 -  pointersLec 40.41 -  pointers
Lec 40.41 - pointers
 
Lec 38.39 - pointers
Lec 38.39 -  pointersLec 38.39 -  pointers
Lec 38.39 - pointers
 
Lec 47.48 - stream-files
Lec 47.48 - stream-filesLec 47.48 - stream-files
Lec 47.48 - stream-files
 
Lec 45.46- virtual.functions
Lec 45.46- virtual.functionsLec 45.46- virtual.functions
Lec 45.46- virtual.functions
 
Lec 37 - pointers
Lec 37 -  pointersLec 37 -  pointers
Lec 37 - pointers
 
Lec 30.31 - inheritance
Lec 30.31 -  inheritanceLec 30.31 -  inheritance
Lec 30.31 - inheritance
 
Lec 28 - operator overloading
Lec 28 - operator overloadingLec 28 - operator overloading
Lec 28 - operator overloading
 
Lec 26.27-operator overloading
Lec 26.27-operator overloadingLec 26.27-operator overloading
Lec 26.27-operator overloading
 
Lec 25 - arrays-strings
Lec 25 - arrays-stringsLec 25 - arrays-strings
Lec 25 - arrays-strings
 
Lec 36 - pointers
Lec 36 -  pointersLec 36 -  pointers
Lec 36 - pointers
 

Lec 33 - inheritance

  • 1. Chapter: 09 Inheritance Lecture: 33 Date: 10.10.2012
  • 3. Public and Private Inheritance class employee //base class { }; class teacher : public employee //publicly-derived { }; class teacher : private employee //privately-derived { };
  • 4. Public and Private Inheritance
  • 5. Levels of Inheritance  Classes can be derived from classes that are themselves derived.
  • 7. Multiple Inheritance  A class can be derived from more than one base class
  • 9. Aggregation: Classes Within Classes  Both inheritance and aggregation are class relationships.  Inheritance is “kind of” relationship - association.  Aggregation is “has a” relationship - association  Def. Aggregation - Several things grouped together or considered as a whole.
  • 10. Aggregation: Classes Within Classes  Both inheritance and aggregation are class relationships.  Inheritance is “kind of” relationship - association.  Aggregation is “has a” relationship - association  Def. Aggregation - Several things grouped together or considered as a whole.
  • 11. Aggregation: Classes Within Classes Aggregation may occur when one object is an attribute of another. In other words, one class contains objects of another class. Example: class A { }; class B { A objA; //object of class A is an attribute of class B };
  • 14. Composition: A Stronger Aggregation  Composition is a stronger form of aggregation, having all its plus two more  The part may belong to only one whole  The lifetime of the part is the same as the lifetime of the whole  While aggregation is a “has a” relationship, composition is a “consists of” relationship.
  • 15. Composition: A Stronger Aggregation  Composition is a stronger form of aggregation, having all its plus two more  The part may belong to only one whole  The lifetime of the part is the same as the lifetime of the whole  While aggregation is a “has a” relationship, composition is a “consists of” relationship.

Editor's Notes

  1. Student Book
  2. Student Book
  3. Student Book
  4. Student Book
  5. Student Book
  6. Student Book
  7. Student Book
  8. Student Book