Originally posted by mohanasundaram muthukannan: Hi,
How can access private constructor in outside the class ?
is any possible?
As the access modifer suggests, it is private and as such cannot be accessed from outside the class. It might be possible with reflection but I haven't tried it out myself.
Usually if you have a private constructor, there is typically a static method which allows you to obtain a reference. This is a classic Singleton pattern.
Is your question from purely an academic point of view or have you encountered a class with a private constructor and are unsure how to use it or are you planning to write a class yourself with a private constructor?
Well said, but Sun could learn from this themselves:
If you know that there are also private fields int offset (the start in value), int count (the number of characters from offset to use) and int hash (the cached hash code, 0 means not cached) you can completely mutate Strings. Not so immutable anymore are they?