abstract class NumberFormat - very confuse about getInstance()
Posted
by Alex
on Stack Overflow
See other posts from Stack Overflow
or by Alex
Published on 2010-03-13T13:34:34Z
Indexed on
2010/03/13
13:45 UTC
Read the original article
Hit count: 489
Hi,
I'm new to Java and I have a beginner question:
NumberFormat is an abstract class and so I assume I can't make an instance of it. But there is a public static (factory?) method getInstance() that allow me to do
NumberFormat nf = NumberFormat.getInstance();
I'm quite confuse. I'll be glad if someone could give me hints on:
1) If there is a public method to get an instance of this abstract class, why don't we have also a constructor?
2) This is an abstract class ; how can we have this static method giving us an instance of the class?
3) Why choosing such a design? If I assume it's possible to have an instance of an abstract class (???), I don't get why this class should be abstract at all.
Thank you.
© Stack Overflow or respective owner