• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

An urgent doubt

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How does the getConnection(....) method of DriverManager class return a Connection object?Connection is an interface and you cannot create object of an interface.Ditto for Statement and ResultSet..Plz explain
 
Ranch Hand
Posts: 1072
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can return a class which implements the interface and catch it as an interface.
interface InterOne{
//...methods
}
public class AnyClass implements InterOne {
public InterOne createCopy(){

return new AnyClass();
}

public AnyClass createAnotherCopy(){

return new AnyClass();
}
}
class AnyTestClass (){
public static void main(String [] args){
AnyClass Test1 = new AnyClass();

InterOne sample = Test1.createCopy();
InterOne anotherSample = Test1.createAnotherCopy();
}
}

And same stuff goes for the abstract class Change Interface declaration to an abstract class
 
Manoj Chandran
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx for reply.But then the object of which class does getConnection method return?
 
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic