Since you cannot create an instance of an interface, no. But you can easily create and return an object that implements that interface.

You can also do so in an anonymous manner. For example:

Now some might say that you are instantiating the interface with this code, but really you are creating an instance of an anonymous class that implements the interface. [ November 09, 2007: Message edited by: Bear Bibeault ]

You can play with instanceof to see which Class is returned by the factory. This adds a level of information hiding to your design. Based on conditions, the factory returns the class that is best suited. The user only sees the interface though and doesn't need to know if they have a class 1 or class2.

This also adds some extensibility, since with this method if a new condition arises requiring Class3, you can simply add it to the factory and leave everything else intact.