Jim Hoglund wrote:If your constructor is private then 'new' will not work (try it). It follows that without an
object, any instance methods cannot be invoked. For example, aa.getName() cannot
work if aa is null. What's the solution - a static method. It works fine without 'new'
because no object is required. Here is a common way to create a MyClass object.
The private constructor is called from within the getInstance() method and the object
created is returned.Jim ... ...
I have another doubt related to this topic
following is a question from self
test answers from K&B
What is the result?
Answer:- alpha subsub
Reason :-SubSubAlpha extends Alpha! Since the code doesn't attempt to make a SubAlpha, the private constructor in SubAlpha is okay
as per the explanation the constuctor "private SubSubAlpha()" is fine bit what i am not able to understand that once this"private SubSubAlpha()" is invoked isn't it that a default call i.e super(); invokes private constructor "private SubAlpha()" so what does the line mean "Since the code doesn't attempt to make a SubAlpha, the private constructor in SubAlpha is okay" ? as per my understanding the answer should be "alpha sub subsub". please correct me if i am wrong
Thanks in advance