Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3965472
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:28:07+00:00 2026-05-20T03:28:07+00:00

I understand how interfaces work in general but I am confused about a thing.

  • 0

I understand how interfaces work in general but I am confused about a thing. I started learning about JDBC and I can’t understand this statement:

Connection conn = null; // set a reference pointing to nothing
Statement stmt = null;
PreparedStatement preparedStmt = null;
conn = DriverManager.getConnection('mysql/derby/other db', 'user', 'password');  

//This is what I don't understand
stmt = conn.createStatement(); // Interface reference calling another interface's method
// Or this
preparedStmt = conn.preparedStatement("INSERT INTO db.table values (?, ?, ?, ?)";

I have a Statement interface reference pointing to another interface’s method Connection interface. Where is this method defined?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:28:07+00:00Added an answer on May 20, 2026 at 3:28 am

    While you can have variables that are of interfaces types (e.g. Connection, Statement, …), the actual objects at runtime need to be of some specific implementation type.

    For example DriverMananger.getConnection() takes over the job of finding the Connection implementation that can handle the JDBC URL you provided.

    Let’s assume that it’s the fictional MyDBConnection class (that implements Connection of course).

    Now your conn variable holds a reference of to a MyDBConnection.

    When you call createStatement() on that object, it’s actually MyDBConnection.createStatement() that gets executed. That method could look like this:

    public Statement createStatement() {
        return new MyDBStatement(this.someConnectionState);
    }
    

    After this, your stmt variable would hold a reference to a MyDBStatement object.

    Remember: if any method promises to return something of type A, it can equally well return something of a sub-type of A (i.e. either a sub-class of A or a class implementing A, if A is an interface). In fact, when A is an interface it has to return a class implementing A. Since a pure A object can’t exist.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I specify interfaces when I declare a member? After thinking about this question
For the record, I've already seen this connect item but I can't really understand
I am new to java and learning interfaces. I did not understand the use
I am struggling to understand on java threads work so excuse this rather simple
So, I understand that the following doesn't work, but why doesn't it work? interface
As I understand interfaces they are contracts, I interpret it as the contract word,
I understand that interfaces are contracts and any changes (even additions) break any dependent
I'm trying to understand Objective-C properties and I have some lingering questions about their
I have a good understanding of OOP in general, inheritance and polymorphism, interfaces, etc.
COM interfaces methods can return various HRESULT values to signal invalid argument values passed.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.