Private constructors

What is worse that can happen if we dont declare private constructor in a class, if it contains only static members
[122 byte] By [Prathima13a] at [2007-10-3 3:04:29]
# 1
what are you talking about?
TuringPesta at 2007-7-14 20:54:30 > top of Java-index,Java Essentials,Java Programming...
# 2

> What is worse that can happen if we dont declare

> private constructor in a class, if it contains only

> static members

Usually you dont declare consturctor as private. declaring constructors

as private means that no other class can create its instance.

You declare constructor as private, when you need to, in certain design

patterns such as singelton pattern. You declare the constructor as a

private and provide a method to get its instance.

Whatever you are talkling about in your question, if you just have a private constructor, then theres no meaning of having that class.

lupansanseia at 2007-7-14 20:54:30 > top of Java-index,Java Essentials,Java Programming...
# 3

> what are you talking about?

When one creates a class with only static methods and data members and instances of the class should never be created then it is normal to provide a private default constructor to stop instances being created.

What is the worst that can happen when the private constructor is not provided and someone creates an instance? No big deal but it does waste a small a bit of memory and small bit of CPU time!

P.S. My mindreading skills are well tuned today!

sabre150a at 2007-7-14 20:54:30 > top of Java-index,Java Essentials,Java Programming...