Object Oriented Programming Techniques (CLASSES)
Object Oriented Programming Techniques (CLASSES)
Programming Techniques
Revision
• Why Classes?
• User defined prototype through which objects are created
• Represents set of properties similar to all objects of one type
• Objects: Represents entities
• Objects consists of:
• State: attributes of an object
• Behavior: method of an object
• Identity: unique name which can interact with other objects
• Memory is utilized for objects
• Objects are accessed through member access operator
Member Variables
Revision float width;
float length;
float area;
Member Functions
void setData(float w, float l)
{ … function code … }
void calcArea(void)
{ … function code … }
void getWidth(void)
{ … function code … }
void getLength(void)
{ … function code … }
void getArea(void)
{ … function code … }
Revision (Write code for class
Dog)
Example
Output
Dry run example code
Constant Member Variable
• Data member used with const keyword
• Cannot be modified after initialization
Constant Member
Variable Example
Output