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 9031727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:48:13+00:00 2026-06-16T07:48:13+00:00

Possible Duplicate: The purpose of interfaces continued I just started learning Java not so

  • 0

Possible Duplicate:
The purpose of interfaces continued

I just started learning Java not so long ago.
I’ve come across Interfaces which I know how to use but still can’t quite grasp the idea of it.
As I understand it, interfaces are usually implemented by classes, which then have to implement the methods declared in the interface.
The problem is – what exactly is the point? Wouldn’t it be easier to just implement the methods from the interface as normal class methods? What exactly are the advantages of using interfaces?

I’ve tried looking for an answer on google. There were many but I still couldn’t understand the point of it. I also read this question and its answers, but the whole contract thing just makes it more complicated…

Hopefully someone could simplify it good enough! 🙂
Thanks in advance!

  • 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-06-16T07:48:15+00:00Added an answer on June 16, 2026 at 7:48 am

    An interface allows you to provide a different implementation at runtime, inject dependencies, separate concerns, use different implementations for testing.

    Just think of an interface as a contract that a class guarantees to implement. The concrete class that implements the interface is irrelevant. Don’t know if this helps.

    Figured some code might help. This doesn’t explain everything there is more to interfaces, keep reading but I hope this gets you started. Point here is that you can vary the implementation…

    package stack.overflow.example;
    
    public interface IExampleService {
    void callExpensiveService();
    }
    
    public class TestService implements IExampleService {
    
    @Override
    public void callExpensiveService() {
        // This is a mock service, we run this as many 
        // times as we like for free to test our software
    
    }
    }
    
    public class ExpensiveService implements IExampleService {
    @Override
    public void callExpensiveService() {
        // This performs some really expensive service,
        // Ideally this will only happen in the field
        // We'd rather test as much of our software for
        // free if possible.
    }
    }
    
    
    public class Main {
    
    /**
     * @param args
     */
    public static void main(String[] args) {
    
        // In a test program I might write
        IExampleService testService = new TestService();
        testService.callExpensiveService();
    
        // Alternatively, in a real program I might write
        IExampleService testService = new ExpensiveService();
        testService.callExpensiveService();
    
        // The difference above, is that we can vary the concrete 
        // class which is instantiated. In reality we can use a 
        // service locator, or use dependency injection to determine 
        // at runtime which class to implement.
    
        // So in the above example my testing can be done for free, but 
        // real world users would still be charged. Point is that the interface
        // provides a contract that we know will always be fulfilled, regardless 
        // of the implementation. 
    
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What’s the purpose of the LEA instruction? Having just started assembly language
Possible Duplicate: What is the purpose of the expression “new String(…)” in Java? What's
Possible Duplicate: What is the purpose of the expression “new String(…)” in Java? I've
Possible Duplicate: What is the purpose of the expression “new String(…)” in Java? It's
Possible Duplicate: What is the purpose of the expression new String(…) in Java? If
Possible Duplicate: Why is client-side validation not enough? What is the purpose of using
Possible Duplicate: Interfaces: Why cant I seem to grasp them? What is the purpose
Possible Duplicate: What is the purpose of the expression “new String(…)” in Java? When
Possible Duplicate: Java Strings: “String s = new String(”silly“);” What is the purpose of
Possible Duplicate: What is the purpose of the expression “new String(…)” in Java? I

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.