oopCPP - Derived d(5,6);...

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

View Full Document Right Arrow Icon
Object Oriented Programming 1. Encapsulation creating a class that contains data ex student data functionality 2. Inheritance student -id* -name* -GPA -# of hours professor -id* -name* -rank -department staff -id* -name* -access level -office location * = have in common super class! person -id -name subclasses student -gpa -hours professor -rank -dept staff
Background image of page 1

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

View Full DocumentRight Arrow Icon
-access level -office location CPP implementation of inheritance class Base{ private: int x; public: Base(int val){ x=val; } int getX(){ return x; } }; class Derived : public Base{ private: int y; public: Derived(int a, int b): Base(a){ y = b; } int getY(){ return y; } }; int main(){ //creates variable d that points to both an object derived and an object Base
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Derived d(5,6); cout<<d.getY()<<endl; // can also do this: cout<< d.getX() << endl; } INHERITANCE DISCUSSED objects are inherited with same visibility as they have in their class so public can be accessed through variable names but private members cannot not inherited: constructors/destructors assignment operator friends order of execution of constructors Top of hierarchy down - base -> derived order of execution of destructors opposite constructors derived -> base class dSquared: public derived{ public: dSquared(int m, int n): derived(m,n){} 3. Polymorphism...
View Full Document

Page1 / 3

oopCPP - Derived d(5,6);...

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

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