-
Junior Member
constructors
hi everybody,
Recently in one interview , i face these questions can anybody help me.
how can we create an instance of a class having the constructor with the private access specifier .
what is the copy constructor and where it is useful in real time
what is singleton class
how can create a class which can't be inheritable.
thanks in Advance
-
Junior Member
Re: constructors
1) Create class instance when the constructor is private
ANS: This is the situation when the owner of the class does not want the control of the constructor or wants to implement specific feature like "singleton". Though the constructor will not be available, there will be some instance creation method so you can always use it to create the instance.
Please let me know if this answer does not clear your doubts.
2) Copy constructor
ANS: Copy constructor can be used to create an instance of a class which is exact duplicate of an existing instance. In programming it can help save time doing all initializations/operations which are needed when creating a new instance of same type of existing one.
3) Singleton class
ANS: The class of which onle one instance can be created. And when user requests for the instance of the class an existant instance is retrived back. This is the case when constructor of the class will be private.
-
Junior Member
Re: constructors
[QUOTE=Rahul C.;13119]1) Create class instance when the constructor is private
ANS: This is the situation when the owner of the class does not want the control of the constructor or wants to implement specific feature like "singleton". Though the constructor will not be available, there will be some instance creation method so you can always use it to create the instance.
Please let me know if this answer does not clear your doubts.
Hi Rahul,
Can you make it clear..? Can you give the exact steps in this case to create an instance
Thanks In Advance
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules