Lecture13_14 - Lecture 13 - Inheritance, Polymorphism,...

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

View Full Document Right Arrow Icon
ECE 3090 Software for Engineering Systems Dr. Ayanna Howard School of Electrical and Computer Engineering Georgia Institute of Technology Lecture 13 - Inheritance, Polymorphism, Virtual Functions
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Adapted from “Brief Version of Starting Out with C++” What Is Inheritance? Provides a way to create a new class from an existing class The new class is a specialized version of the existing class
Background image of page 2
3 Adapted from “Brief Version of Starting Out with C++” The ‘is a’ Relationship An object of a derived class 'is a(n)' object of the base class A derived object has all of the characteristics of the base class Inheritance establishes an "is a" relationship between classes. A poodle is a dog A car is a vehicle A flower is a plant A football player is an athlete
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Adapted from “Brief Version of Starting Out with C++” Inheritance – Terminology and Notation Base class (or parent) – inherited from Derived class (or child) – inherits from the base class Notation: class Student // base class { . . . }; class UnderGrad : public Student { // derived class . . . };
Background image of page 4
5 Adapted from “Brief Version of Starting Out with C++” What Does a Child Have? An object of the derived class has: all members defined in child class all members declared in parent class An object of the derived class can use: all public members defined in child class all public members defined in parent class An object of the derived class cannot use: private members defined in parent class
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Adapted from “Brief Version of Starting Out with C++” Inheritance private: char letter; float score; void calcGrade(); public: void setScore(float); float getScore(); char getLetter(); class Grade private: int numQuestions; float pointsEach; int numMissed; public: Test(int, int); class Test : public Grade When Test class inherits from Grade class, it looks like this: private members: int numQuestions: float pointsEach; int numMissed; public members: Test(int, int); void setScore(float); float getScore(); float getLetter(); Test testVar; testVar.numQuestions = 5; // Valid testVar.setScore(2.0); // Valid testVar.score = 5; // ERROR
Background image of page 6
7 Adapted from “Brief Version of Starting Out with C++” Protected Members protected member access specification: like private , but accessible by objects of derived class
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 Adapted from “Brief Version of Starting Out with C++” Inheritance protected: float score; private: char letter; void calcGrade(); public: void setScore(float); float getScore(); char getLetter(); class Grade private: int numQuestions; float pointsEach; int numMissed; public: Test(int, int); class Test : public Grade When Test class inherits from Grade class, it looks like this: private members: int numQuestions: float pointsEach; int numMissed; float score; public members: Test(int, int); void setScore(float); float getScore(); float getLetter(); Test testVar; testVar.numQuestions = 5; // Valid testVar.setScore(2.0); // Valid testVar.score = 5; // Valid
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/09/2009 for the course ECE 3090 taught by Professor Staff during the Fall '08 term at Georgia Institute of Technology.

Page1 / 81

Lecture13_14 - Lecture 13 - Inheritance, Polymorphism,...

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

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