WHERE AND HOW CAN YOU USE A PRIVATE CONSTRUCTOR IN JAVA?

Sumit Kesarwani

Total Post:782

Points:3910
Posted by  Sumit Kesarwani
Java 
 1337  View(s)
Ratings:
Rate this:
  1. Sumit Kesarwani

    Post:782

    Points:3910
    Where and how can you use a private constructor in java?

     Private constructor is used if you do not want other classes to instantiate the object and to prevent sub-classing. The instantiate is done by a public static method (i.e. a static factory method) within the same class.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!