Semester : SEMESTER 6
Subject : Object Oriented Programming
Year : 2018
Term : MARCH
Scheme : 2015 Full Time
Course Code : EC 312
Page:11
double breadth; // Breadth of a box
double height; // Height of a box
|);
int main(void) {
Box Box1(3.3, 1.2, 1.5); // Declare 1
Box Box2(8.5, 6.9, 2.0); // Declare box2
Box *ptrBox; // Declare pointer to a class.
// Save the address of first object
ptrBox = &Box1;
// Now try to access a member using member access operator
cout << “Volume of 8041: " << ptrBox->Volume() << endl;
// Save the addres
ptrBox = &Box2
// Now try to access a member using member access operator
cout << "Volume of Box2: " << ptrBox->Volume() << endl;
return 6;
When the above code is compiled and executed, it produces the following
result —
Constructor called.
Constructor called.
Volume of Box1: 5.94
Volume of Box2: 102
4b. Function Overloading (achieved at compile time)