close

一般來說 , 宣告在private區域就是代表部給class以外的人使用 , 

所以若把constructor宣告在private區域 , 代表就是不可以對這個class instantize.

So...you should use private constructor when you don't want anyone outside the class to invoke that particular constructor.

The most common use that I see for private (and protected) constructors is in implementing singletons and some types of object factories. 

Basically, you use a static method to manage the creation of one (or more) instances of the class.

arrow
arrow
    全站熱搜

    JerryCheng 發表在 痞客邦 留言(0) 人氣()