1.

Which among the following is correct?(a) class student{ public: int student(){} };(b) class student{ public: void student (){} };(c) class student{ public: student{}{}};(d) class student{ public: student(){} };I had been asked this question in an interview for internship.Asked question is from Constructors topic in portion Constructors and Destructors of Object Oriented Programming

Answer»

Right option is (d) class STUDENT{ public: student(){} };

Explanation: The constructors must not have any RETURN type. Also, the body may or may not contain any body. Defining DEFAULT constructor is optional, if you are not USING any other constructor.



Discussion

No Comment Found

Related InterviewSolutions