Question #251728

Q2: Answer the questions (i) and (iii) after going through the following class:
class Seminar
{
int time;
public:
Seminar() //Function 1
{
time = 30;
cout << "Seminar starts now" << endl;
}
void lecture() //Function 2
{
cout << "Lectures in the seminar on" << endl;
}
Seminar(int duration) //Function 3
{
time = duration;
cout << "Seminar starts now" << endl;
}
~Seminar() //Function 4
{
cout << "Thanks" << endl;
}
};
i. Write statements in C++ that would execute Function 1 and Function 3 of class Seminar.
ii. In Object Oriented Programming, what is Function 4 referred as and when does it get invoked/called?
iii. In Object Oriented Programming, which concept is illustrated by Function 1 and Function 3 together?

Expert's answer

1.

Seminar default_ctor; // func 1
Seminar other_ctor(10); // func 3

2.It's a destructor. It's being invoked when the object is going to be destroyed, i.e. object is out of scope where it's been created.

3.They are constructors (default and with parameter)


LATEST TUTORIALS
APPROVED BY CLIENTS