Results 1 to 3 of 3

Thread: constructors

  1. #1
    Junior Member
    Join Date
    Jun 2007
    Answers
    1

    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


  2. #2
    Junior Member
    Join Date
    May 2007
    Answers
    4

    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.


  3. #3

    Question 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
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact