Inheritance (Extending Classes)

Question

Answer the question (i) and (ii) after going through the following class :

class Travel
{
	int PlaceCode; char Place[20]; float Charges; public:
Travel( )	//Function 1
{
	PlaceCode=1;strcpy(Place,”DELHI”);Charges=1000;
}
void TravelPlan(float C )	// Function 2
{
	cout<<PlaceCode<<“:”<<Place<<”:”<<Charges<<endl;
}
~Travel( )	// Function 3
{
	cout<<”Travel Plan Cancelled”<<endl;
}
Travel(int PC,char p[],float C)	// Function 4
{
	PlaceCode=PC;strcpy(Place,P);Charges=c;
}

(i) In Object Oriented Programming, what are Function 1 and Function 4 combined together referred as?

(ii) In Object Oriented Programming, which concept is illustrated by Function 3? When is this function called/invoked?

Answer

(i) Polymorphism or Constructor Overloading
(ii) Function 3: Destructor

A destructor called/invoked when an object of that class is destroyed. When a variable goes out of scope, or a dynamically allocated variable is explicitly deleted using the delete keyword, the class destructor is called to help clean up the class before it is removed from memory.

Sponsor Area

Some More Questions From Inheritance (Extending Classes) Chapter