which relationship between private constructor and derivation class

Discussion in 'Meet and Greet' started by gorangk, Mar 2, 2007.

  1. gorangk

    gorangk New Member

    Joined:
    Mar 1, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    which relationship between private constructor and derivation class that derivation is not possible
    (meaning constructor implements the actions required to initialize an instance)
    mean - stop create instance ok, but derive class ?
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    I could not get what you are looking for?
     
  3. gorangk

    gorangk New Member

    Joined:
    Mar 1, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    thank for time,so
    at few place i see that private constructors in class, arrest
    1) create instances of the class
    2) for other class to derive from the class
    i can't see logic for the second point
    ************************************************************
    microsoft -c# language specifications-page 215
    When a class declares only private constructors it is not possible for other classes to derive from the
    class or create instances of the class (an exception being classes nested within the class). Private
    constructors are commonly used in classes that contain only static members. For example:
    ***************************************************************
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Private constructor makes a class
    1. singleton by exposing the instance of the object. As constructor is private you cannot create the objects but are bound to use the predefined method to get the object of the class.
    2. You cannot derive a class from the class which has private constructor.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice