SlideShare a Scribd company logo
Inheritance Concept class Rectangle{   private:   int numVertices;   float *xCoord, *yCoord;   public:   void set(float *x, float *y, int nV);   float area(); }; Rectangle Triangle Polygon class Polygon{   private: int numVertices; float *xCoord, *yCoord;   public: void set(float *x, float *y, int nV); }; class Triangle{   private:   int numVertices; float *xCoord, *yCoord;   public: void set(float *x, float *y, int nV);   float area(); };
Inheritance Concept Rectangle Triangle Polygon class Polygon{ protected:   int numVertices;   float *xCoord, float *yCoord; public:   void set(float *x, float *y, int nV); }; class Rectangle : public Polygon{ public:     float  area(); }; class Rectangle{ protected:   int numVertices;   float *xCoord, float *yCoord; public:   void set(float *x, float *y, int nV);   float area(); };
Inheritance Concept Rectangle Triangle Polygon class Polygon{ protected:   int numVertices;   float *xCoord, float *yCoord; public:   void set(float *x, float *y, int nV); }; class Triangle : public Polygon{ public:   float area(); }; class Triangle{ protected:   int numVertices;   float *xCoord, float *yCoord; public:   void set(float *x, float *y, int nV);   float area(); };
Inheritance Concept Point Circle 3D-Point class Point{ protected:   int x, y; public:   void set (int a, int b); }; class Circle : public Point{ private:  double r; }; class 3D-Point: public Point{ private:  int z; }; x y x y r x y z
[object Object],[object Object],Inheritance Concept RealNumber ComplexNumber ImaginaryNumber Rectangle Triangle Polygon Point Circle real imag real imag 3D-Point
Why Inheritance ? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Define a Class Hierarchy ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Class Derivation Point 3D-Point class Point{ protected:   int x, y; public:   void set (int a, int b); }; class 3D-Point : public Point{ private:  double z; … … }; class Sphere : public 3D-Point{ private:  double r; … … }; Sphere Point  is the base class of  3D-Point , while  3D-Point  is the base class of  Sphere
What to inherit? ,[object Object],[object Object]
Access Control Over the Members ,[object Object],[object Object],[object Object],class Point{ protected:  int x, y; public:  void set(int a, int b); }; class Circle :  public  Point{ … … };
[object Object],Access Rights of Derived Classes Type of Inheritance Access Control for Members public protected private public protected protected private protected - - - private public protected private
Class Derivation class daughter :  ---------  mother{ private: double dPriv; public: void mFoo ( ); }; class mother{ protected:  int mProc; public:  int mPubl; private:  int  mPriv; }; class daughter :  ---------  mother{ private: double dPriv; public: void dFoo ( ); }; void daughter :: dFoo ( ){ mPriv = 10;   //error mProc = 20; }; private/protected/public int main() { /*….*/ } class grandDaughter :  public  daughter { private: double gPriv; public: void gFoo ( ); };
What to inherit? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Constructor Rules for Derived Classes  ,[object Object],class A { public: A ( )   {cout<< “A:default”<<endl;} A (int a)   {cout<<“A:parameter”<<endl;} }; class B : public A  { public:  B (int a)   {cout<<“B”<<endl;} }; B test(1); A:default B output:
Constructor Rules for Derived Classes  ,[object Object],class A { public: A ( )   {cout<< “A:default”<<endl;} A (int a)   {cout<<“A:parameter”<<endl;} }; class C : public A { public:  C (int a) : A(a)   {cout<<“C”<<endl;} }; C test(1); A:parameter C output: ,[object Object],[object Object]
Define its Own Members Point Circle class Point{ protected:   int x, y; public:   void set(int a, int b); }; class Circle : public Point{ private:  double r; public: void set_r(double c); }; x y x y r class Circle{ protected:   int x, y; private:   double r; public:   void set(int a, int b);   void set_r(double c); }; The derived class can also define its own members,  in addition to the members inherited from the base class
Even more … ,[object Object],[object Object],[object Object],class A { protected: int x, y; public: void print () {cout<<“From A”<<endl;} }; class B : public A { public:  void print ()   {cout<<“From B”<<endl;} };
class Point{ protected:   int x, y; public:   void  set (int a, int b) {x=a; y=b;}   void  foo  ();   void  print (); }; class Circle : public Point{ private:  double r; public: void  set  (int a, int b, double c) {   Point :: set(a, b);  //same name function call   r = c; } void  print ();  }; Access a Method Circle C; C. set (10,10,100);  // from class Circle C. foo  ();  // from base class Point C. print (); // from class Circle Point A; A. set (30,50);  // from base class Point A. print ();  // from base class Point
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Putting Them Together ExtTime Time
class   Time  Specification ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],// SPECIFICATION  FILE  ( time.h)
Class Interface Diagram Protected data: hrs mins secs Set Increment Write Time Time Time   class
Derived Class  ExtTime   ,[object Object],[object Object],[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 Interface Diagram Protected data: hrs mins secs ExtTime   class Set Increment Write Time Time Set Increment Write ExtTime ExtTime Private data: zone
Implementation of  ExtTime ,[object Object],[object Object],[object Object],[object Object],Default Constructor The default constructor of base class, Time(), is automatically called, when an ExtTime object is created. ExtTime et1; hrs = 0 mins = 0 secs = 0 zone = EST et1
Implementation of  ExtTime ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Another Constructor ExtTime *et2 =  new ExtTime(8,30,0,EST); hrs = 8 mins = 30 secs = 0 zone = EST et2 5000 ??? 6000 5000
Implementation of  ExtTime ,[object Object],[object Object],[object Object],[object Object],[object Object],void  ExtTime :: Write ( )  const  // function overriding { string  zoneString[8] =  {“EST”, “CST”, MST”, “PST”, “EDT”, “CDT”, “MDT”, “PDT”} ; Time :: Write ( ) ; cout  <<‘  ‘<<zoneString[zone]<<endl; }
Working with   ExtTime ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Take Home Message ,[object Object],[object Object]

More Related Content

What's hot

ddd+scala
ddd+scaladdd+scala
ddd+scala
潤一 加藤
 
Virtual function
Virtual functionVirtual function
Virtual function
harman kaur
 
Objective-Cひとめぐり
Objective-CひとめぐりObjective-Cひとめぐり
Objective-Cひとめぐり
Kenji Kinukawa
 
Multiple inheritance in c++
Multiple inheritance in c++Multiple inheritance in c++
Multiple inheritance in c++
Saket Pathak
 
Constructors & destructors
Constructors & destructorsConstructors & destructors
Constructors & destructors
ForwardBlog Enewzletter
 
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
PROIDEA
 
C++ L09-Classes Part2
C++ L09-Classes Part2C++ L09-Classes Part2
C++ L09-Classes Part2
Mohammad Shaker
 
Decorated Attribute Grammars (CC 2009)
Decorated Attribute Grammars (CC 2009)Decorated Attribute Grammars (CC 2009)
Decorated Attribute Grammars (CC 2009)
lennartkats
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
Christian Baranowski
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
Jussi Pohjolainen
 
개발 과정 최적화 하기 내부툴로 더욱 강력한 개발하기 Stephen kennedy _(11시40분_103호)
개발 과정 최적화 하기 내부툴로 더욱 강력한 개발하기 Stephen kennedy _(11시40분_103호)개발 과정 최적화 하기 내부툴로 더욱 강력한 개발하기 Stephen kennedy _(11시40분_103호)
개발 과정 최적화 하기 내부툴로 더욱 강력한 개발하기 Stephen kennedy _(11시40분_103호)
changehee lee
 
20.2 Java inheritance
20.2 Java inheritance20.2 Java inheritance
20.2 Java inheritance
Intro C# Book
 
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + ProcessingRoberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
Demetrio Siragusa
 
11. Objects and Classes
11. Objects and Classes11. Objects and Classes
11. Objects and Classes
Intro C# Book
 
Code as data as code.
Code as data as code.Code as data as code.
Code as data as code.
Mike Fogus
 
11. Java Objects and classes
11. Java  Objects and classes11. Java  Objects and classes
11. Java Objects and classes
Intro C# Book
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
Hans Höchtl
 
Object calisthenics
Object calisthenicsObject calisthenics
Object calisthenics
PolSnchezManzano
 
Exhibition of Atrocity
Exhibition of AtrocityExhibition of Atrocity
Exhibition of Atrocity
Michael Pirnat
 
from java to c
from java to cfrom java to c
from java to c
Võ Hòa
 

What's hot (20)

ddd+scala
ddd+scaladdd+scala
ddd+scala
 
Virtual function
Virtual functionVirtual function
Virtual function
 
Objective-Cひとめぐり
Objective-CひとめぐりObjective-Cひとめぐり
Objective-Cひとめぐり
 
Multiple inheritance in c++
Multiple inheritance in c++Multiple inheritance in c++
Multiple inheritance in c++
 
Constructors & destructors
Constructors & destructorsConstructors & destructors
Constructors & destructors
 
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
 
C++ L09-Classes Part2
C++ L09-Classes Part2C++ L09-Classes Part2
C++ L09-Classes Part2
 
Decorated Attribute Grammars (CC 2009)
Decorated Attribute Grammars (CC 2009)Decorated Attribute Grammars (CC 2009)
Decorated Attribute Grammars (CC 2009)
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
 
개발 과정 최적화 하기 내부툴로 더욱 강력한 개발하기 Stephen kennedy _(11시40분_103호)
개발 과정 최적화 하기 내부툴로 더욱 강력한 개발하기 Stephen kennedy _(11시40분_103호)개발 과정 최적화 하기 내부툴로 더욱 강력한 개발하기 Stephen kennedy _(11시40분_103호)
개발 과정 최적화 하기 내부툴로 더욱 강력한 개발하기 Stephen kennedy _(11시40분_103호)
 
20.2 Java inheritance
20.2 Java inheritance20.2 Java inheritance
20.2 Java inheritance
 
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + ProcessingRoberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
 
11. Objects and Classes
11. Objects and Classes11. Objects and Classes
11. Objects and Classes
 
Code as data as code.
Code as data as code.Code as data as code.
Code as data as code.
 
11. Java Objects and classes
11. Java  Objects and classes11. Java  Objects and classes
11. Java Objects and classes
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Object calisthenics
Object calisthenicsObject calisthenics
Object calisthenics
 
Exhibition of Atrocity
Exhibition of AtrocityExhibition of Atrocity
Exhibition of Atrocity
 
from java to c
from java to cfrom java to c
from java to c
 

Viewers also liked

Mahadi The role of indigenous gums and resins in pastoralist livelihood secur...
Mahadi The role of indigenous gums and resins in pastoralist livelihood secur...Mahadi The role of indigenous gums and resins in pastoralist livelihood secur...
Mahadi The role of indigenous gums and resins in pastoralist livelihood secur...
futureagricultures
 
CLIMATE CHANGE IMPLICATIONS ON FOOD AND AGRICUTURE IN AFRICA
CLIMATE CHANGE IMPLICATIONS ON FOOD AND AGRICUTURE IN AFRICACLIMATE CHANGE IMPLICATIONS ON FOOD AND AGRICUTURE IN AFRICA
CLIMATE CHANGE IMPLICATIONS ON FOOD AND AGRICUTURE IN AFRICA
RUFORUM
 
1 21
1 211 21
1 21
Les Davy
 
World I: Module 6
World I: Module 6World I: Module 6
World I: Module 6
gbgupresentations
 
день героев отечества
день героев отечествадень героев отечества
день героев отечестваelvira38
 
Q 4 week 2
Q 4 week 2Q 4 week 2
Q 4 week 2
Les Davy
 
Household items for sport
Household items for sportHousehold items for sport
Household items for sport
Cecilia Aguilar
 
Asthma Presentation
Asthma PresentationAsthma Presentation
Asthma Presentation
AC Tambago
 
Oap
OapOap
Researchers - recommendations from AIGLIA2014
Researchers - recommendations from AIGLIA2014Researchers - recommendations from AIGLIA2014
Researchers - recommendations from AIGLIA2014
futureagricultures
 
Assessing enablers and constrainers of graduation
Assessing enablers and constrainers of graduationAssessing enablers and constrainers of graduation
Assessing enablers and constrainers of graduation
futureagricultures
 
Destroying property
Destroying propertyDestroying property
Destroying property
candice santiago
 
Hyperactivity
HyperactivityHyperactivity
Hyperactivity
candice santiago
 
Fighting cleanup routines
Fighting cleanup routinesFighting cleanup routines
Fighting cleanup routines
candice santiago
 
Xavier thoma
Xavier thomaXavier thoma
Xavier thoma
xavierthoma
 
Evaluation Question 4
Evaluation Question 4Evaluation Question 4
Evaluation Question 4
Sammi Wilde
 
01 05-14
01 05-1401 05-14
01 05-14
Carlos Carvalho
 

Viewers also liked (20)

Mahadi The role of indigenous gums and resins in pastoralist livelihood secur...
Mahadi The role of indigenous gums and resins in pastoralist livelihood secur...Mahadi The role of indigenous gums and resins in pastoralist livelihood secur...
Mahadi The role of indigenous gums and resins in pastoralist livelihood secur...
 
CLIMATE CHANGE IMPLICATIONS ON FOOD AND AGRICUTURE IN AFRICA
CLIMATE CHANGE IMPLICATIONS ON FOOD AND AGRICUTURE IN AFRICACLIMATE CHANGE IMPLICATIONS ON FOOD AND AGRICUTURE IN AFRICA
CLIMATE CHANGE IMPLICATIONS ON FOOD AND AGRICUTURE IN AFRICA
 
Comicus-Markedsføring-2015
Comicus-Markedsføring-2015Comicus-Markedsføring-2015
Comicus-Markedsføring-2015
 
1 21
1 211 21
1 21
 
World I: Module 6
World I: Module 6World I: Module 6
World I: Module 6
 
день героев отечества
день героев отечествадень героев отечества
день героев отечества
 
Q 4 week 2
Q 4 week 2Q 4 week 2
Q 4 week 2
 
Household items for sport
Household items for sportHousehold items for sport
Household items for sport
 
Agenda robert guzman
Agenda robert guzmanAgenda robert guzman
Agenda robert guzman
 
affTA02 - BAB II
affTA02 - BAB IIaffTA02 - BAB II
affTA02 - BAB II
 
Asthma Presentation
Asthma PresentationAsthma Presentation
Asthma Presentation
 
Oap
OapOap
Oap
 
Researchers - recommendations from AIGLIA2014
Researchers - recommendations from AIGLIA2014Researchers - recommendations from AIGLIA2014
Researchers - recommendations from AIGLIA2014
 
Assessing enablers and constrainers of graduation
Assessing enablers and constrainers of graduationAssessing enablers and constrainers of graduation
Assessing enablers and constrainers of graduation
 
Destroying property
Destroying propertyDestroying property
Destroying property
 
Hyperactivity
HyperactivityHyperactivity
Hyperactivity
 
Fighting cleanup routines
Fighting cleanup routinesFighting cleanup routines
Fighting cleanup routines
 
Xavier thoma
Xavier thomaXavier thoma
Xavier thoma
 
Evaluation Question 4
Evaluation Question 4Evaluation Question 4
Evaluation Question 4
 
01 05-14
01 05-1401 05-14
01 05-14
 

Similar to Lecture4

Inheritance.pptx
Inheritance.pptxInheritance.pptx
Inheritance.pptx
RutujaTandalwade
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining Classes
Intro C# Book
 
inhertance c++
inhertance c++inhertance c++
inhertance c++
abhilashagupta
 
Inheritance
InheritanceInheritance
Inheritance
poonam.rwalia
 
Inheritance in C++.ppt
Inheritance in C++.pptInheritance in C++.ppt
Inheritance in C++.ppt
instaface
 
C++ Language
C++ LanguageC++ Language
C++ Language
Vidyacenter
 
Inheritance
InheritanceInheritance
Inheritance
Mustafa Khan
 
Inheritance
InheritanceInheritance
Inheritance
Tech_MX
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
FALLEE31188
 
C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 preview
Paulo Morgado
 
Basics of objective c
Basics of objective cBasics of objective c
Basics of objective c
sagaroceanic11
 
c++-language-1208539706757125-9.pdf
c++-language-1208539706757125-9.pdfc++-language-1208539706757125-9.pdf
c++-language-1208539706757125-9.pdf
nisarmca
 
Chapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-classChapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-class
Deepak Singh
 
Object-oriented Basics
Object-oriented BasicsObject-oriented Basics
Object-oriented Basics
Jamie (Taka) Wang
 
Lab3
Lab3Lab3
Inheritance
InheritanceInheritance
Inheritance
GowriLatha1
 
OOP Lab Report.docx
OOP Lab Report.docxOOP Lab Report.docx
OOP Lab Report.docx
ArafatSahinAfridi
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
BG Java EE Course
 
Review constdestr
Review constdestrReview constdestr
Review constdestr
rajudasraju
 
inheritance c++
inheritance c++inheritance c++
inheritance c++
Muraleedhar Sundararajan
 

Similar to Lecture4 (20)

Inheritance.pptx
Inheritance.pptxInheritance.pptx
Inheritance.pptx
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining Classes
 
inhertance c++
inhertance c++inhertance c++
inhertance c++
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance in C++.ppt
Inheritance in C++.pptInheritance in C++.ppt
Inheritance in C++.ppt
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 preview
 
Basics of objective c
Basics of objective cBasics of objective c
Basics of objective c
 
c++-language-1208539706757125-9.pdf
c++-language-1208539706757125-9.pdfc++-language-1208539706757125-9.pdf
c++-language-1208539706757125-9.pdf
 
Chapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-classChapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-class
 
Object-oriented Basics
Object-oriented BasicsObject-oriented Basics
Object-oriented Basics
 
Lab3
Lab3Lab3
Lab3
 
Inheritance
InheritanceInheritance
Inheritance
 
OOP Lab Report.docx
OOP Lab Report.docxOOP Lab Report.docx
OOP Lab Report.docx
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
 
Review constdestr
Review constdestrReview constdestr
Review constdestr
 
inheritance c++
inheritance c++inheritance c++
inheritance c++
 

More from FALLEE31188

Lecture2
Lecture2Lecture2
Lecture2
FALLEE31188
 
L16
L16L16
L2
L2L2
Inheritance
InheritanceInheritance
Inheritance
FALLEE31188
 
Inheritance
InheritanceInheritance
Inheritance
FALLEE31188
 
Functions
FunctionsFunctions
Functions
FALLEE31188
 
Field name
Field nameField name
Field name
FALLEE31188
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
FALLEE31188
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
FALLEE31188
 
Cis068 08
Cis068 08Cis068 08
Cis068 08
FALLEE31188
 
Chapter14
Chapter14Chapter14
Chapter14
FALLEE31188
 
Chapt03
Chapt03Chapt03
Chapt03
FALLEE31188
 
C++lecture9
C++lecture9C++lecture9
C++lecture9
FALLEE31188
 
C++ polymorphism
C++ polymorphismC++ polymorphism
C++ polymorphism
FALLEE31188
 
C1320prespost
C1320prespostC1320prespost
C1320prespost
FALLEE31188
 
Brookshear 06
Brookshear 06Brookshear 06
Brookshear 06
FALLEE31188
 
Book ppt
Book pptBook ppt
Book ppt
FALLEE31188
 
Assignment 2
Assignment 2Assignment 2
Assignment 2
FALLEE31188
 
Assignment
AssignmentAssignment
Assignment
FALLEE31188
 
5 2
5 25 2

More from FALLEE31188 (20)

Lecture2
Lecture2Lecture2
Lecture2
 
L16
L16L16
L16
 
L2
L2L2
L2
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Functions
FunctionsFunctions
Functions
 
Field name
Field nameField name
Field name
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
Cis068 08
Cis068 08Cis068 08
Cis068 08
 
Chapter14
Chapter14Chapter14
Chapter14
 
Chapt03
Chapt03Chapt03
Chapt03
 
C++lecture9
C++lecture9C++lecture9
C++lecture9
 
C++ polymorphism
C++ polymorphismC++ polymorphism
C++ polymorphism
 
C1320prespost
C1320prespostC1320prespost
C1320prespost
 
Brookshear 06
Brookshear 06Brookshear 06
Brookshear 06
 
Book ppt
Book pptBook ppt
Book ppt
 
Assignment 2
Assignment 2Assignment 2
Assignment 2
 
Assignment
AssignmentAssignment
Assignment
 
5 2
5 25 2
5 2
 

Recently uploaded

clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 

Recently uploaded (20)

clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 

Lecture4

  • 1. Inheritance Concept class Rectangle{ private: int numVertices; float *xCoord, *yCoord; public: void set(float *x, float *y, int nV); float area(); }; Rectangle Triangle Polygon class Polygon{ private: int numVertices; float *xCoord, *yCoord; public: void set(float *x, float *y, int nV); }; class Triangle{ private: int numVertices; float *xCoord, *yCoord; public: void set(float *x, float *y, int nV); float area(); };
  • 2. Inheritance Concept Rectangle Triangle Polygon class Polygon{ protected: int numVertices; float *xCoord, float *yCoord; public: void set(float *x, float *y, int nV); }; class Rectangle : public Polygon{ public: float area(); }; class Rectangle{ protected: int numVertices; float *xCoord, float *yCoord; public: void set(float *x, float *y, int nV); float area(); };
  • 3. Inheritance Concept Rectangle Triangle Polygon class Polygon{ protected: int numVertices; float *xCoord, float *yCoord; public: void set(float *x, float *y, int nV); }; class Triangle : public Polygon{ public: float area(); }; class Triangle{ protected: int numVertices; float *xCoord, float *yCoord; public: void set(float *x, float *y, int nV); float area(); };
  • 4. Inheritance Concept Point Circle 3D-Point class Point{ protected: int x, y; public: void set (int a, int b); }; class Circle : public Point{ private: double r; }; class 3D-Point: public Point{ private: int z; }; x y x y r x y z
  • 5.
  • 6.
  • 7.
  • 8. Class Derivation Point 3D-Point class Point{ protected: int x, y; public: void set (int a, int b); }; class 3D-Point : public Point{ private: double z; … … }; class Sphere : public 3D-Point{ private: double r; … … }; Sphere Point is the base class of 3D-Point , while 3D-Point is the base class of Sphere
  • 9.
  • 10.
  • 11.
  • 12. Class Derivation class daughter : --------- mother{ private: double dPriv; public: void mFoo ( ); }; class mother{ protected: int mProc; public: int mPubl; private: int mPriv; }; class daughter : --------- mother{ private: double dPriv; public: void dFoo ( ); }; void daughter :: dFoo ( ){ mPriv = 10; //error mProc = 20; }; private/protected/public int main() { /*….*/ } class grandDaughter : public daughter { private: double gPriv; public: void gFoo ( ); };
  • 13.
  • 14.
  • 15.
  • 16. Define its Own Members Point Circle class Point{ protected: int x, y; public: void set(int a, int b); }; class Circle : public Point{ private: double r; public: void set_r(double c); }; x y x y r class Circle{ protected: int x, y; private: double r; public: void set(int a, int b); void set_r(double c); }; The derived class can also define its own members, in addition to the members inherited from the base class
  • 17.
  • 18. class Point{ protected: int x, y; public: void set (int a, int b) {x=a; y=b;} void foo (); void print (); }; class Circle : public Point{ private: double r; public: void set (int a, int b, double c) { Point :: set(a, b); //same name function call r = c; } void print (); }; Access a Method Circle C; C. set (10,10,100); // from class Circle C. foo (); // from base class Point C. print (); // from class Circle Point A; A. set (30,50); // from base class Point A. print (); // from base class Point
  • 19.
  • 20.
  • 21. Class Interface Diagram Protected data: hrs mins secs Set Increment Write Time Time Time class
  • 22.
  • 23. Class Interface Diagram Protected data: hrs mins secs ExtTime class Set Increment Write Time Time Set Increment Write ExtTime ExtTime Private data: zone
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.