Chapter12 - Chapter 12 Inheritance 1 Dr. Serdar Kirli...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Dr. Serdar Kirli 1 Chapter 12 Inheritance
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Dr. Serdar Kirli 2 Inheritance Inheritance allows to create classes which are derived from other classes, so that they automatically include some of its "parent's" members, plus its own courtesy of http://www.cplusplus.com , 11/28/06
Background image of page 2
Dr. Serdar Kirli 3 “Protected” members The protected access specifier is similar to private. Its only difference occurs in fact with inheritance. When a class inherits from another one, the members of the derived class can access the protected members inherited from the base class, but not its private members. courtesy of http://www.cplusplus.com , 11/28/06
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Dr. Serdar Kirli 4 Access specifiers courtesy of http://www.cplusplus.com , 11/28/06 Access public protected private members of the same class yes yes yes members of derived classes yes yes no not members yes no no
Background image of page 4
Dr. Serdar Kirli 5 Example Polygon Rectangle Triangle courtesy of http://www.cplusplus.com , 11/28/06
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Dr. Serdar Kirli 6 Polygon Inheritance Example courtesy of http://www.cplusplus.com , 11/28/06 #include <iostream> using namespace std; class Polygon { protected : int width; int height; public : Polygon() { width = height = 0; } void setValues( int a, int b) { width = a; height = b; } };
Background image of page 6
Dr. Serdar Kirli 7 Polygon Inheritance Example courtesy of http://www.cplusplus.com , 11/28/06 #include <iostream> using namespace std; class Polygon { public : Polygon() { width = height = 0; }
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 23

Chapter12 - Chapter 12 Inheritance 1 Dr. Serdar Kirli...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online