• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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?
 
Police line, do not cross. Well, this tiny ad can go through:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic