SlideShare a Scribd company logo
Inheritance
[object Object],[object Object],[object Object],[object Object],Reuse
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Vehicle wheels engine Car wheels engine trunk Truck wheels engine trailer trunk trailer base class sub-classes or derived classes
[object Object],[object Object],[object Object],[object Object],[object Object]
 
 
 
 
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object]
 
[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Base class Derived  class Derived class Shape class Triangle  class Circle class Right-angle Triangle Equilateral Triangle Isosceles Triangle
[object Object],[object Object],Shape class Triangle  class Circle class Right-angle Triangle Equilateral Triangle Isosceles Triangle Shape class Triangle  class Circle class Right-angle Triangle Equilateral Triangle Isosceles Triangle
student print() year_group() CR print() inherits (isa) student_id, year, name dept, thesis
 
[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],The derived class inherits from the base class:  all public members  (see later) The additional members defined can have the same name (and type) as those   of the base class (as when some base members are to be redefined)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object]
class  Shape {  protected :  int  width, height;  public :  void  setDims ( int  a,  int  b){  width=a; height=b;}  };  class  Rectangle:  public  Shape {  public :  int  area ( ) {  return  (width * height);  } };   class  Triangle:  public  Shape {  public :  int  area ( ) {  return  (width * height/2);  } }; class  Square:  public  Rectangle {  public : void  setDims ( int  a){  width=a; height=a;} };
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object]
 
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Animal Display() zoo[0]->Display(); zoo[1]->Display(); zoo[2]->Display(); Dog Display() Cat Display()
 
Inheritance Hierarchy for Person-derived Classes
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object]
[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object]
[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object]
[object Object],[object Object],[object Object]
[object Object]
[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object]
[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object]
[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
public inheritance protected inheritance private inheritance public  member in base class public  in derived class protected  in derived class private  in derived class protected  member in base class protected  in derived class protected  in derived class private  in derived class private  member in base class hidden in derived class hidden in derived class hidden in derived class
[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],15-
[object Object],[object Object],[object Object],[object Object],15- Animal Cat Dog Poodle
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],15-
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],15-
[object Object],[object Object],15-
[object Object],[object Object],[object Object],[object Object],15-
[object Object],15-
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],15-
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],15-
[object Object],[object Object],[object Object],15-
[object Object],[object Object],[object Object],15-
[object Object],[object Object],[object Object],[object Object],15-
[object Object],[object Object],[object Object],[object Object],15- B1 B2 D
[object Object],[object Object],15-
[object Object],15- B D1 D2 D3
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],15-
[object Object],[object Object],[object Object],Unit 02
[object Object],[object Object],[object Object],Unit 02 ,[object Object]
[object Object],[object Object],15-
[object Object],[object Object],15-
[object Object],[object Object],[object Object],15-
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],15-
[object Object],[object Object],15-
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Unit 02 Employee class must be abstract because each type of employee has different pay rate and pay calculation is different. So we make is abstract by making the pay function as pure virtual.
class HourlyEmployee: Employee { private: int hours; public:   void getdata(){  {   Employee::getdata();   cout<<&quot; Enter number of hours worked....&quot;;   cin>>hours;    } void toString() {  Employee::toString();   cout<<&quot; Hours worked...&quot;<<hours;   }   double pay() {   return payRate * hours;   } }; Pay() function must to be redefined
[object Object],[object Object],Unit 02
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],We are defining the class person as Abstract class because it provides interface for the class student and professor.  The functions getdata() and is_outstanding() are pure virtual and needs to be redefined in each derived class  This class saves the data of students and professors which are of person type. The program finds the out_standing students and professors.
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],15- We are defining the class person as Abstract class because it provides interface for the class student and professor.  The functions getdata() and is_outstanding() are pure virtual and needs to be redefined in each derived class. A student is outstanding if his GPA is more than 3.75 and getdata() fucntion calls getname() function of person class.
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],15- Professor class creates the getdata() function and calls the person class function getname() and number of publications. Professor is outstanding if his publications are more than 10.
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],15- Ptr is a pointers array of base class (person). Due to pointer it can point to derived class objects like student and professor.
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],15- Now the array ptr has the record of students and professors. Because of pointers the dynamic binding is applied which needs the function to be defined as virtual. Because of virtual function is_outstanding() is called accordingly.
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Unit 02
[object Object],[object Object],Unit 02
[object Object],[object Object],[object Object],[object Object],[object Object],Unit 02
[object Object],[object Object],15-
[object Object],[object Object],[object Object],[object Object],[object Object],Unit 01
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Unit 02
[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],Car Vehicle A car is ‘a kind of’ vehicle car class can inherit from  vehicle class
[object Object],Car Wheel  A wheel isn’t ‘a kind of’ car. A wheel is ‘a part of’ a car  - this is dealt with by aggregation which is this week’s topic
[object Object],[object Object]
[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object]
class Wheel { private: int diameter; public: Wheel(int diameter_in){ diameter = diameter_in; } int getDiameter() { return diameter; } }; class Engine  { private: int cc; public: Engine(int cc_in)  { cc = cc_in; } int getCC()return cc; } };
class Car { private: Wheel nearside_front, offside_front,  nearside_rear, offside_rear; Engine engine; int passengers; public: Car(int diameter_in, int cc_in, int passengers_in); void showSelf(); };
Car::Car(int diameter_in, int cc_in, int passengers_in) : nearside_front(diameter_in), offside_front(diameter_in), nearside_rear(diameter_in), offside_rear(diameter_in), engine(cc_in) ‏ { passengers = passengers_in; }
15-
HL 1. Main component / sub component Composition Aggregation &quot;contains &quot; relation &quot;has&quot; relation: Main component &quot;has&quot; a sub component as a part. 2. Association &quot;owns&quot; &quot;knows&quot; &quot;uses&quot; &quot;serves“ “ observes” etc. 3.  Generalisation / specialisation Inheritance General case / Special case Super class / Sub class Base class / Derived class Base class / Inherited class &quot;is&quot; relation. An instance of derived class &quot;is&quot; an instance of base class.
HL Composition means same as  - contains - is part of Example 1. Point can be a sub component of Circle. class Circle { public: Circle(float x0=0.0, float y0=0.0, r0=0.0); Circle(const Point &cp0, r0=0.0); private: float r; Point cp;  //sub component }; Constuctor implementation on the next page.   Example 2. Date can be used as a data member in class Person: class Person {   public:   Person(const string& name, int year,  int month, int day);   Person(const string& name, const Date& bd);   private:   string name;  // sub component 1   Date birthDay;  // sub component 2 };
HL An object can have an object as a subcomponent. In this example circles have a point as a subcomponent (representing their center point  */ #include <iostream.h> //Class definition of Point class Point { public: Point(float x0=0.0, float y0=0.0); void read(); void print(); private: float x; float y; }; //Class definition of Circle class Circle{ public: Circle(float x0=0.0, float y0=0.0, float r0=0.0); Circle(const Point &cp0, float r0=0.0); void read(); void print(); private: float radius; Point centerPoint; };
HL //Application void main (void) { Point p(11.0, 12.0); Circle c1, c2(1.0, 2.0, 10.0), c3(p, 20.0); c1.print(); c2.print(); c3.print(); } //Member function implementations //Member functions of Point Point::Point(float x0, float y0) { x = x0; y = y0; } void Point :: read() { cout << &quot; x-coordinate: &quot;; cin >> x; cout << &quot; y-coordinate: &quot;; cin >> y; } void Point :: print() { cout << &quot;(&quot;  << x << &quot;,&quot; << y <<  &quot;)&quot;; }
HL //Member functions of Circle //Constructor 1 version 1 Circle::Circle(float x0, float y0, float r0): centerPoint(x0, y0){ radius = r0; } /* Constructor 1 version 2  (Point constructor is called twice) Circle::Circle(float x0, float y0, float r0) { radius = r0; centerPoint = Point(x0, y0); } */ //Constructor 2 version 1 Circle::Circle(const Point &cp0, float r0):centerPoint(cp0){ radius = r0; } /*Constructor 2 version 2  (Point constructor is called twice) Circle::Circle(const Point &cp0, float r0) { radius = r0; centerPoint = Point(cp0);  //Default copy constructor of Point } */ void Circle :: read() { cout << &quot;Enter radius : &quot;; cin >> radius; cout << &quot;Enter centerpoint :&quot;; centerPoint.read(); } void Circle :: print() { cout << &quot;The circle data is :&quot;; cout << &quot;Radius is : &quot; << radius; cout << &quot;Center point is :&quot;; centerPoint.print(); }
HL Memory allocation is done at the same time (as one block of memory) for the main component and for sub component, because sub component is part of the memory area of the main component. The object is created in the following phases: 1. Memory is allocated for the whole object. 2. The constructor call of sub component class that is defined in the initialisation list of main component is executed. If there is no sub component constructor call in the initialisation list, the default constructor of sub component is called.  3. The function body of main component constructor is called. This rule of order means that it is guaranteed that sub component is already constructed when constructor body on main component is executed. It also guarantees that sub components are always initialised at least with default constructor of sub component class. This is useful as you can understand thinking about the differences between defining a name member in the Person class as char *name or  string name!. The implementor of the Person class needs to do many things in the former case but almost nothing in the latter case.
HL When an object containing a sub-component object is de-allocated, the things happen in the following order: 1.The destructor of the main component is called first. 2. The destructor of the sub-component is called next. 3. The memory area is de-allocated as a whole. The  default assignment  operator  of the main component:  If we don’t overload the assignment operator in the main component class the default assignment is used. If we have overloaded assignment for the sub-component that is used in the default assignment when sub-component part is copied. The  default copy constructor  of the main component:  If we don’t write the copy constructor for the main component class the default copy constructor is used. If we have written copy constructor for the sub-component it is used in the default copy constructor when sub-component part is constructed.
[object Object],[object Object],[object Object],[object Object],Unit 02
[object Object],[object Object],15-
[object Object],[object Object],[object Object],[object Object],[object Object],Unit 01

More Related Content

What's hot

Support for Object-Oriented Programming (OOP) in C++
Support for Object-Oriented Programming (OOP) in C++Support for Object-Oriented Programming (OOP) in C++
Support for Object-Oriented Programming (OOP) in C++
Ameen Sha'arawi
 
#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop InheritanceHadziq Fabroyir
 
Class and object
Class and objectClass and object
Class and object
prabhat kumar
 
C++ oop
C++ oopC++ oop
C++ oop
Sunil OS
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
prabhat kumar
 
OOP C++
OOP C++OOP C++
OOP C++
Ahmed Farag
 
C++ Multiple Inheritance
C++ Multiple InheritanceC++ Multiple Inheritance
C++ Multiple Inheritanceharshaltambe
 
inhertance c++
inhertance c++inhertance c++
inhertance c++
abhilashagupta
 
Inheritance
InheritanceInheritance
Inheritance
prabhat kumar
 
Inheritance
InheritanceInheritance
Inheritance
Burhan Ahmed
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorialsFALLEE31188
 
2CPP14 - Abstraction
2CPP14 - Abstraction2CPP14 - Abstraction
2CPP14 - Abstraction
Michael Heron
 
Inheritance chepter 7
Inheritance chepter 7Inheritance chepter 7
Inheritance chepter 7
kamal kotecha
 
Chapter 06 constructors and destructors
Chapter 06 constructors and destructorsChapter 06 constructors and destructors
Chapter 06 constructors and destructors
Praveen M Jigajinni
 
Chapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-classChapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-classDeepak Singh
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining Classes
Intro C# Book
 
Inheritance
InheritanceInheritance
Inheritance
Jancirani Selvam
 
Inheritance : Extending Classes
Inheritance : Extending ClassesInheritance : Extending Classes
Inheritance : Extending Classes
Nilesh Dalvi
 
Learn Concept of Class and Object in C# Part 3
Learn Concept of Class and Object in C#  Part 3Learn Concept of Class and Object in C#  Part 3
Learn Concept of Class and Object in C# Part 3
C# Learning Classes
 
pointers,virtual functions and polymorphism
pointers,virtual functions and polymorphismpointers,virtual functions and polymorphism
pointers,virtual functions and polymorphism
rattaj
 

What's hot (20)

Support for Object-Oriented Programming (OOP) in C++
Support for Object-Oriented Programming (OOP) in C++Support for Object-Oriented Programming (OOP) in C++
Support for Object-Oriented Programming (OOP) in C++
 
#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance
 
Class and object
Class and objectClass and object
Class and object
 
C++ oop
C++ oopC++ oop
C++ oop
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
OOP C++
OOP C++OOP C++
OOP C++
 
C++ Multiple Inheritance
C++ Multiple InheritanceC++ Multiple Inheritance
C++ Multiple Inheritance
 
inhertance c++
inhertance c++inhertance c++
inhertance c++
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
2CPP14 - Abstraction
2CPP14 - Abstraction2CPP14 - Abstraction
2CPP14 - Abstraction
 
Inheritance chepter 7
Inheritance chepter 7Inheritance chepter 7
Inheritance chepter 7
 
Chapter 06 constructors and destructors
Chapter 06 constructors and destructorsChapter 06 constructors and destructors
Chapter 06 constructors and destructors
 
Chapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-classChapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-class
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining Classes
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance : Extending Classes
Inheritance : Extending ClassesInheritance : Extending Classes
Inheritance : Extending Classes
 
Learn Concept of Class and Object in C# Part 3
Learn Concept of Class and Object in C#  Part 3Learn Concept of Class and Object in C#  Part 3
Learn Concept of Class and Object in C# Part 3
 
pointers,virtual functions and polymorphism
pointers,virtual functions and polymorphismpointers,virtual functions and polymorphism
pointers,virtual functions and polymorphism
 

Viewers also liked

20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles
Intro C# Book
 
Idiomatic C++
Idiomatic C++Idiomatic C++
Idiomatic C++
Federico Ficarelli
 
The Style of C++ 11
The Style of C++ 11The Style of C++ 11
The Style of C++ 11
Sasha Goldshtein
 
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMS
fawzmasood
 
Distributed Systems Design
Distributed Systems DesignDistributed Systems Design
Distributed Systems Design
Dennis van der Stelt
 
Operator overloading
Operator overloadingOperator overloading
Operator overloadingfarhan amjad
 
Improving The Quality of Existing Software
Improving The Quality of Existing SoftwareImproving The Quality of Existing Software
Improving The Quality of Existing Software
Steven Smith
 
C++ Advanced
C++ AdvancedC++ Advanced
C++ AdvancedVivek Das
 
Inheritance chapter-6-computer-science-with-c++ opt
Inheritance chapter-6-computer-science-with-c++ optInheritance chapter-6-computer-science-with-c++ opt
Inheritance chapter-6-computer-science-with-c++ opt
deepakskb2013
 
Lecture4
Lecture4Lecture4
Lecture4
rajesh0ks
 
abitha-pds inheritance presentation
abitha-pds inheritance presentationabitha-pds inheritance presentation
abitha-pds inheritance presentationabitha ben
 
Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1
PRN USM
 
Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...
Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...
Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...
Complement Verb
 
Web Service Basics and NWS Setup
Web Service  Basics and NWS SetupWeb Service  Basics and NWS Setup
Web Service Basics and NWS Setup
Northeastern University
 
Chapter 04 inheritance
Chapter 04 inheritanceChapter 04 inheritance
Chapter 04 inheritance
Nurhanna Aziz
 
Polymorphism (2)
Polymorphism (2)Polymorphism (2)
Operator overloading
Operator overloading Operator overloading
Operator overloading
Northeastern University
 
An Introduction to Part of C++ STL
An Introduction to Part of C++ STLAn Introduction to Part of C++ STL
An Introduction to Part of C++ STL
乐群 陈
 
Inheritance question class 12th
Inheritance question class 12thInheritance question class 12th
Inheritance question class 12th
AAKASH KUMAR
 

Viewers also liked (20)

20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles
 
Inheritance
InheritanceInheritance
Inheritance
 
Idiomatic C++
Idiomatic C++Idiomatic C++
Idiomatic C++
 
The Style of C++ 11
The Style of C++ 11The Style of C++ 11
The Style of C++ 11
 
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMS
 
Distributed Systems Design
Distributed Systems DesignDistributed Systems Design
Distributed Systems Design
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Improving The Quality of Existing Software
Improving The Quality of Existing SoftwareImproving The Quality of Existing Software
Improving The Quality of Existing Software
 
C++ Advanced
C++ AdvancedC++ Advanced
C++ Advanced
 
Inheritance chapter-6-computer-science-with-c++ opt
Inheritance chapter-6-computer-science-with-c++ optInheritance chapter-6-computer-science-with-c++ opt
Inheritance chapter-6-computer-science-with-c++ opt
 
Lecture4
Lecture4Lecture4
Lecture4
 
abitha-pds inheritance presentation
abitha-pds inheritance presentationabitha-pds inheritance presentation
abitha-pds inheritance presentation
 
Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1
 
Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...
Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...
Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...
 
Web Service Basics and NWS Setup
Web Service  Basics and NWS SetupWeb Service  Basics and NWS Setup
Web Service Basics and NWS Setup
 
Chapter 04 inheritance
Chapter 04 inheritanceChapter 04 inheritance
Chapter 04 inheritance
 
Polymorphism (2)
Polymorphism (2)Polymorphism (2)
Polymorphism (2)
 
Operator overloading
Operator overloading Operator overloading
Operator overloading
 
An Introduction to Part of C++ STL
An Introduction to Part of C++ STLAn Introduction to Part of C++ STL
An Introduction to Part of C++ STL
 
Inheritance question class 12th
Inheritance question class 12thInheritance question class 12th
Inheritance question class 12th
 

Similar to Inheritance, polymorphisam, abstract classes and composition)

Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methodsfarhan amjad
 
00ps inheritace using c++
00ps inheritace using c++00ps inheritace using c++
00ps inheritace using c++
sushamaGavarskar1
 
inheritance
inheritanceinheritance
inheritance
Amir_Mukhtar
 
OOP Lab Report.docx
OOP Lab Report.docxOOP Lab Report.docx
OOP Lab Report.docx
ArafatSahinAfridi
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
Swarup Boro
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
SURBHI SAROHA
 
Chapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).pptChapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).ppt
henokmetaferia1
 
Hello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdfHello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdf
irshadkumar3
 
class c++
class c++class c++
class c++
vinay chauhan
 
Chap-3 Inheritance.pptx
Chap-3 Inheritance.pptxChap-3 Inheritance.pptx
Chap-3 Inheritance.pptx
chetanpatilcp783
 
Lecture 5 Inheritance
Lecture 5 InheritanceLecture 5 Inheritance
Lecture 5 Inheritancebunnykhan
 
Java Generics
Java GenericsJava Generics
Java Generics
jeslie
 
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptxinheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
urvashipundir04
 
02-OOP with Java.ppt
02-OOP with Java.ppt02-OOP with Java.ppt
02-OOP with Java.ppt
EmanAsem4
 
INHERITANCE.pptx
INHERITANCE.pptxINHERITANCE.pptx
INHERITANCE.pptx
AteeqaKokab1
 
C++ programming public, private inheritance
C++ programming public, private inheritanceC++ programming public, private inheritance
C++ programming public, private inheritance
bilalisb999
 
OOP Concepets and UML Class Diagrams
OOP Concepets and UML Class DiagramsOOP Concepets and UML Class Diagrams
OOP Concepets and UML Class Diagrams
Bhathiya Nuwan
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
shubhra chauhan
 

Similar to Inheritance, polymorphisam, abstract classes and composition) (20)

Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
 
00ps inheritace using c++
00ps inheritace using c++00ps inheritace using c++
00ps inheritace using c++
 
inheritance
inheritanceinheritance
inheritance
 
OOP Lab Report.docx
OOP Lab Report.docxOOP Lab Report.docx
OOP Lab Report.docx
 
Inheritance
InheritanceInheritance
Inheritance
 
Java Basic day-2
Java Basic day-2Java Basic day-2
Java Basic day-2
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
 
Chapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).pptChapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).ppt
 
Hello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdfHello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdf
 
class c++
class c++class c++
class c++
 
Chap-3 Inheritance.pptx
Chap-3 Inheritance.pptxChap-3 Inheritance.pptx
Chap-3 Inheritance.pptx
 
Lecture 5 Inheritance
Lecture 5 InheritanceLecture 5 Inheritance
Lecture 5 Inheritance
 
Java Generics
Java GenericsJava Generics
Java Generics
 
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptxinheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
 
02-OOP with Java.ppt
02-OOP with Java.ppt02-OOP with Java.ppt
02-OOP with Java.ppt
 
INHERITANCE.pptx
INHERITANCE.pptxINHERITANCE.pptx
INHERITANCE.pptx
 
C++ programming public, private inheritance
C++ programming public, private inheritanceC++ programming public, private inheritance
C++ programming public, private inheritance
 
OOP Concepets and UML Class Diagrams
OOP Concepets and UML Class DiagramsOOP Concepets and UML Class Diagrams
OOP Concepets and UML Class Diagrams
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
 

Recently uploaded

Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 

Recently uploaded (20)

Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 

Inheritance, polymorphisam, abstract classes and composition)

  • 2.
  • 3.
  • 4.
  • 5.  
  • 6.  
  • 7.  
  • 8.  
  • 9.
  • 10.
  • 11.  
  • 12.
  • 13.
  • 14. Base class Derived class Derived class Shape class Triangle class Circle class Right-angle Triangle Equilateral Triangle Isosceles Triangle
  • 15.
  • 16. student print() year_group() CR print() inherits (isa) student_id, year, name dept, thesis
  • 17.  
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23. class Shape { protected : int width, height; public : void setDims ( int a, int b){ width=a; height=b;} }; class Rectangle: public Shape { public : int area ( ) { return (width * height); } }; class Triangle: public Shape { public : int area ( ) { return (width * height/2); } }; class Square: public Rectangle { public : void setDims ( int a){ width=a; height=a;} };
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.  
  • 31.
  • 32.
  • 33.
  • 34. Animal Display() zoo[0]->Display(); zoo[1]->Display(); zoo[2]->Display(); Dog Display() Cat Display()
  • 35.  
  • 36. Inheritance Hierarchy for Person-derived Classes
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110. public inheritance protected inheritance private inheritance public member in base class public in derived class protected in derived class private in derived class protected member in base class protected in derived class protected in derived class private in derived class private member in base class hidden in derived class hidden in derived class hidden in derived class
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138.
  • 139.
  • 140.
  • 141.
  • 142.
  • 143.
  • 144.
  • 145.
  • 146.
  • 147.
  • 148.
  • 149.
  • 150.
  • 151.
  • 152.
  • 153.
  • 154.
  • 155.
  • 156.
  • 157.
  • 158.
  • 159.
  • 160.
  • 161. class HourlyEmployee: Employee { private: int hours; public: void getdata(){ { Employee::getdata(); cout<<&quot; Enter number of hours worked....&quot;; cin>>hours; } void toString() { Employee::toString(); cout<<&quot; Hours worked...&quot;<<hours; } double pay() { return payRate * hours; } }; Pay() function must to be redefined
  • 162.
  • 163.
  • 164.
  • 165.
  • 166.
  • 167.
  • 168.
  • 169.
  • 170.
  • 171.
  • 172.
  • 173.
  • 174.
  • 175.
  • 176.
  • 177.
  • 178.
  • 179.
  • 180.
  • 181.
  • 182. class Wheel { private: int diameter; public: Wheel(int diameter_in){ diameter = diameter_in; } int getDiameter() { return diameter; } }; class Engine { private: int cc; public: Engine(int cc_in) { cc = cc_in; } int getCC()return cc; } };
  • 183. class Car { private: Wheel nearside_front, offside_front, nearside_rear, offside_rear; Engine engine; int passengers; public: Car(int diameter_in, int cc_in, int passengers_in); void showSelf(); };
  • 184. Car::Car(int diameter_in, int cc_in, int passengers_in) : nearside_front(diameter_in), offside_front(diameter_in), nearside_rear(diameter_in), offside_rear(diameter_in), engine(cc_in) ‏ { passengers = passengers_in; }
  • 185. 15-
  • 186. HL 1. Main component / sub component Composition Aggregation &quot;contains &quot; relation &quot;has&quot; relation: Main component &quot;has&quot; a sub component as a part. 2. Association &quot;owns&quot; &quot;knows&quot; &quot;uses&quot; &quot;serves“ “ observes” etc. 3. Generalisation / specialisation Inheritance General case / Special case Super class / Sub class Base class / Derived class Base class / Inherited class &quot;is&quot; relation. An instance of derived class &quot;is&quot; an instance of base class.
  • 187. HL Composition means same as - contains - is part of Example 1. Point can be a sub component of Circle. class Circle { public: Circle(float x0=0.0, float y0=0.0, r0=0.0); Circle(const Point &cp0, r0=0.0); private: float r; Point cp; //sub component }; Constuctor implementation on the next page. Example 2. Date can be used as a data member in class Person: class Person { public: Person(const string& name, int year, int month, int day); Person(const string& name, const Date& bd); private: string name; // sub component 1 Date birthDay; // sub component 2 };
  • 188. HL An object can have an object as a subcomponent. In this example circles have a point as a subcomponent (representing their center point */ #include <iostream.h> //Class definition of Point class Point { public: Point(float x0=0.0, float y0=0.0); void read(); void print(); private: float x; float y; }; //Class definition of Circle class Circle{ public: Circle(float x0=0.0, float y0=0.0, float r0=0.0); Circle(const Point &cp0, float r0=0.0); void read(); void print(); private: float radius; Point centerPoint; };
  • 189. HL //Application void main (void) { Point p(11.0, 12.0); Circle c1, c2(1.0, 2.0, 10.0), c3(p, 20.0); c1.print(); c2.print(); c3.print(); } //Member function implementations //Member functions of Point Point::Point(float x0, float y0) { x = x0; y = y0; } void Point :: read() { cout << &quot; x-coordinate: &quot;; cin >> x; cout << &quot; y-coordinate: &quot;; cin >> y; } void Point :: print() { cout << &quot;(&quot; << x << &quot;,&quot; << y << &quot;)&quot;; }
  • 190. HL //Member functions of Circle //Constructor 1 version 1 Circle::Circle(float x0, float y0, float r0): centerPoint(x0, y0){ radius = r0; } /* Constructor 1 version 2 (Point constructor is called twice) Circle::Circle(float x0, float y0, float r0) { radius = r0; centerPoint = Point(x0, y0); } */ //Constructor 2 version 1 Circle::Circle(const Point &cp0, float r0):centerPoint(cp0){ radius = r0; } /*Constructor 2 version 2 (Point constructor is called twice) Circle::Circle(const Point &cp0, float r0) { radius = r0; centerPoint = Point(cp0); //Default copy constructor of Point } */ void Circle :: read() { cout << &quot;Enter radius : &quot;; cin >> radius; cout << &quot;Enter centerpoint :&quot;; centerPoint.read(); } void Circle :: print() { cout << &quot;The circle data is :&quot;; cout << &quot;Radius is : &quot; << radius; cout << &quot;Center point is :&quot;; centerPoint.print(); }
  • 191. HL Memory allocation is done at the same time (as one block of memory) for the main component and for sub component, because sub component is part of the memory area of the main component. The object is created in the following phases: 1. Memory is allocated for the whole object. 2. The constructor call of sub component class that is defined in the initialisation list of main component is executed. If there is no sub component constructor call in the initialisation list, the default constructor of sub component is called. 3. The function body of main component constructor is called. This rule of order means that it is guaranteed that sub component is already constructed when constructor body on main component is executed. It also guarantees that sub components are always initialised at least with default constructor of sub component class. This is useful as you can understand thinking about the differences between defining a name member in the Person class as char *name or string name!. The implementor of the Person class needs to do many things in the former case but almost nothing in the latter case.
  • 192. HL When an object containing a sub-component object is de-allocated, the things happen in the following order: 1.The destructor of the main component is called first. 2. The destructor of the sub-component is called next. 3. The memory area is de-allocated as a whole. The default assignment operator of the main component: If we don’t overload the assignment operator in the main component class the default assignment is used. If we have overloaded assignment for the sub-component that is used in the default assignment when sub-component part is copied. The default copy constructor of the main component: If we don’t write the copy constructor for the main component class the default copy constructor is used. If we have written copy constructor for the sub-component it is used in the default copy constructor when sub-component part is constructed.
  • 193.
  • 194.
  • 195.

Editor's Notes

  1. The reusability is a key benefit of OO programming. By reusing the code the development effort is thus reduced. The time can further be spent in making the software reliable and ROBUST
  2. Example: Design an application, teachers and the principal (director) in a school. First, assume that we have a class to define teachers, then we can use this class to model the principal. Because the principal is a teacher.
  3. See inheritance4.h and pr15-02.cpp
  4. See inheritance6.h and pr15-05.cpp
  5. See pr15-04.cpp