C++ Programming - Constructors and Destructors - Discussion

Discussion Forum : Constructors and Destructors - General Questions (Q.No. 8)
8.
Which of the following statement is incorrect?
Constructor is a member function of the class.
The compiler always provides a zero argument constructor.
It is necessary that a constructor in a class should always be public.
Both B and C.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
34 comments Page 4 of 4.

Kavitha josephine said:   1 decade ago
Is it necessary to specify access specifier to a constructor each time its created.

Ghanshyam said:   1 decade ago
Constructor must always public only...
define it with private or protected always cause compile time error...
try following code and check..
/* Note: GCC Compiler (32 Bit Linux Platform). */

#include<iostream.h>
class one
{
private:
int a;
protected:
one(){a=0;}
public:
void show()
{
cout<<"yes..";
}
};

int main()
{
one obj;
obj.show();
getch();
return 0;
}

Myth said:   1 decade ago
Can any one say how many argument is provided by compiler to a constructor by default.

Ravi said:   1 decade ago
For option C, if a constructor is private, then what is the use of that if we can't create an object of that class.

If we try to create object of a class whose constructor is private, it will give error :: constructor () is private.


Post your comments here:

Your comments will be displayed after verification.