+ 6
Why do we need private constructors?
Because we can't instantiate an object from these kind of classes. Could you explain when do we need it?
5 Antworten
+ 3
makes your code more secure when you use private
+ 3
Now, I understand my mistake. We can use it in another class like this(I am trying to establish a relationship between inheritance and private constructor, that is why I am confused):
class one{
string take;
one(string pass)
{
take=pass
}
};
class two{
one obj("hey");
};
+ 3
I confuse when I see the function return types as class. 😟 I need to learn this kind of functions. Where could I learn it? @Vukan
0
I think private constructors are useful when the program needs a concept called self referenciation i.e.,the object of a class is created within the same class. So that the objects cannot be created in other classes. And according to the requirement of program.
Am I right? 🤔