snip from http://www.javaworld.com/javaworld/jw-03-1999/jw-03-howto.html
The ConnectionFactory, QueueConnectionFactory, and TopicConnectionFactory interfaces represent administered objects. They encapsulate a set of configuration parameters that have been defined by an administrator. A client uses a ConnectionFactory to create a Connection with a JMS provider. They simplify the administration of a message service in a large-scale enterprise setting. ConnectionFactory objects support concurrent use.
So to summarize it, magic ;)
There is only one object bound into jndi that
implements both interfaces. You choose the
interface to use with the cast.