If you don't write your own constructor, the compiler will generate a constructor for you.
If a constructor is not public, it can't be used outside of a class and it can't be called by methods that are not a part of the class.
What's the use of making a constructor private:
- The constructor can only be accessed from static factory method inside the class itself. Singleton can also belong to this category.
- A utility class, that only contains static methods.
Overloading Constructors
You can overload constructors as you can overload any method.
0 comments:
Post a Comment