| Author |
Object of Interfaces
|
Ankitt Gupta
Ranch Hand
Joined: Feb 19, 2009
Posts: 101
|
|
Hi Ranchers
As we know we can't make objects of interfaces.But while writing JDBC codes the getConnection() method returns Connection object...How?
Please clarify this
|
 |
Jan Cumps
Bartender
Joined: Dec 20, 2006
Posts: 2343
|
|
It returns an object that implements Connection.
Regards, Jan
|
OCUP UML fundamental
ITIL foundation
|
 |
Ankitt Gupta
Ranch Hand
Joined: Feb 19, 2009
Posts: 101
|
|
Jan Cumps wrote:It returns an object that implements Connection.
Regards, Jan
Thanks for replying Jan
You mean to say that there is some anonymous class that implements it?
|
 |
Kiran Joshi
Ranch Hand
Joined: Sep 04, 2005
Posts: 54
|
|
The implementing class is not required to be anonymous.
It is provided through the jars you keep in your classpath.
for example ojdbc14.jar or classes12.jar provided by db vendors like (oracle) or third parties that provide jdbc drivers.
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26184
|
|
|
Right. The interface is so you don't refer to the concrete class. That way you can change databases/drivers without changing your code.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
 |
|
|
subject: Object of Interfaces
|
|
|