• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Constructors in a class

 
Ravi Hyd
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know whether we can create a Private default constructor in a class. Can anybody explain what is Singleton class?
 
Manuel Moons
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it is possible to create a private default Constructor.

If all constructors are private you cannot create an instance from outside that class.

If you create a public static method that always returns the same instance of that class you have used the singleton pattern.

Look at the example:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic