C++ Programming - Constructors and Destructors - Discussion
Discussion Forum : Constructors and Destructors - General Questions (Q.No. 8)
8.
Which of the following statement is incorrect?
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;
}
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.
If we try to create object of a class whose constructor is private, it will give error :: constructor () is private.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers