|
Re: Class with private constructor
|
Posted: Mar 15, 2004 5:09 AM
|
|
> Thanks all. I tried both solution with my Eclipse. Why i > have an compilation error if the class Sundae makeSundae > is not a static class???
I think David has already answered this, above. If a method is not static then it can only be called via an instance of the class. For example:Sundae s2 = s1.makeSundae();
This means that you need an existing instance to create a new instance. That's OK except that you won't be able to create a first instance to start things off (because the constructor is private). Therefore, the makeSundae method needs to be static so that you can write the following:Sundae s = Sundae.makeSundae();
Vince.
|
|