+2 votes
in Class 12 by kratos

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

class Exam

{

int Rollno;

char Cname[25];

float Marks ;

public :

Exam( ) //Function 1

Rollno = 0 ;

Cname=””;

Marks=0.0;

}

Exam(int Rno, char candname) //Function 2

{

Rollno = Rno ;

strcpy(Cname,candname);

}

~Exam( ) //Function 3

{

cout << “Result will be intimated shortly” << endl ;

}

void Display( ) //Function 4

{

cout << “Roll no :”<<Rollno;

cout<<”Name :” <<Cname;

cout <<” Marks:”<<Marks;

}

} ;

(i) Which OOP concept does Function 1 and Function 2 implement.Explain?

(ii) What is Function 3 called? When will it be invoked?

1 Answer

+6 votes
by kratos
 
Best answer

(i) Constructor Overloading /Polymorphism, as multiple definitions for Constructors, are given in the same scope. Function 1 is a Default constructor and function 2 is a Parameterized constructor.

(ii) Function 3 is a Destructor which is invoked when the object goes out of scope.

...