• Post Reply Bookmark Topic Watch Topic
  • New Topic

Here connectionFactory is an interface. how am i directly being able to access the method getConnec  RSS feed

 
Sowm Herur
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I have a piece of code

Here connectionFactory is an interface. how am i directly being able to access the method getConnection() of this interface ConnectionFactory.
Here connection Factory is not a static class so that i can directly gain access to its method getConnection() without creating an instance.


Connection connection=null;
connection=connectionFactory.getConnection();

Can somebody please explain me this?

file:///C:/j2ee_connectorapi/doc/api/index.html

 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Here connection Factory is not a static class so that i can directly gain access to its method getConnection() without creating an instance.

Not sure what this means. Can you explain what you are asking?
 
Sowm Herur
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Let me come to the basics:

To access any method we need to create an instance or if the class is static we can directly access it using the classname.

in this example ConnectionFactory is an interface.

In this code

Connection connection=null;
connection=connectionFactory.getConnection();

Then how are we able to access the method getConnection() when there is no instance created nor is the ConnectionFactory a static class?

 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't, plain and simple. Something must implement the interface and you call the getConnection() method on that implementation. The code you have listed will not complie.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!