lec0209-inherit - Todays announcements: MP2 available, due...

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

View Full Document Right Arrow Icon
Today’s announcements: MP2 available, due 2/11, 11:59p. Lab03 will be continued this week, and it will be graded. DYB today, 3-5p, Siebel 2407.
Background image of page 1

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

View Full DocumentRight Arrow Icon
Inheritance: a simple first example class sphere { public: sphere(); sphere(double r); double getVolume(); void setRadius(double r); void display(); private: double theRadius; }; class ball:public sphere { public: ball(); ball(double r string n); string getName(); void setName(string n); void display(); private: string name; }; Base class: Derived class: ball b;
Background image of page 2
class sphere { public: sphere(); sphere(double r); double getVolume(); void setRadius(double r); void display(); private: double theRadius; }; class ball:public sphere { public: ball(); ball(double r string n); string getName(); void setName(string n); void display(); private: string name; }; Protected access: like public to derived classes, like private to anything else ball b; b.color = “red”;
Background image of page 3

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

View Full DocumentRight Arrow Icon
Subclass substitution (via examples): sphere s(8.0); ball b(3.2, “pompom”); double a = b.getVolume(); void printVolume(sphere t){ cout << t.getVolume() << endl;} printVolume(s); printVolume(b); Base b; Derived d; Base * b;
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/26/2012 for the course CS CS 225 taught by Professor Heeren during the Spring '09 term at University of Illinois, Urbana Champaign.

Page1 / 10

lec0209-inherit - Todays announcements: MP2 available, due...

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

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