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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:21:06+00:00 2026-06-18T05:21:06+00:00

So I looked online through a number of resources to understand Java interfaces. I

  • 0

So I looked online through a number of resources to understand Java interfaces. I believe I have a good general understanding of them but when programming them I am a bit confused…

I created an interface called A and have the following inside…

    public interface A {
    public int sum(int first, int second);
}

I then created a class called B.

public class B implements A {

    public static void main(String [] args){
        int result = sum(3, 5);
    }

    public int sum(int first, int second) {
        int total = first + second;
        return total;
    }

}

Now what I am trying to figure out is how can I properly call / use the method “sum”. In Eclipse I’m getting an error for the line “int result = sum(3, 5);” and it is telling me to make the method static. If I make it static, then the method needs to match it in the interface. However, I am not able to use static methods in an interface?

Any help is appreciated and thank you for your time to read about my problems.

  • 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-18T05:21:07+00:00Added an answer on June 18, 2026 at 5:21 am

    The issue you have is not of interface but of static method.

    main is a static method. That means it is not linked to an object/instance, but to the class itself.

    Since you want to use sum, which is an instance method, you need first to create an object to call its method.

    A a = new B();
    int result = a.sum(5, 6);
    

    Usually, instance methods are more linked to the object status, while static methods are more like “procedures” in non OO languages. In the case of sum, your method would make more sense as static. But, if you use B to wrap a value (status), and use sum to add to your internal status, this would end (in a more OO friendly way).

    A a = new B(5);
    a.sum(6);
    int result = a.getValue();
    

    Note that both approachs are valid and both compile in Java, it is just a matter of selecting the modifiers that make more sense in each occasion.

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

Sidebar

Related Questions

I have looked at the php documentation, tutorials online and none of them how
I've looked through the CPython sources ( Hg online here ), but I can't
I've got it to work, and I have looked online and through the documentation,
I looked online for some references but didn't have too much luck. Hopefully it's
I have looked online and i havent been able to fix a problem that
I looked around but haven't found an answer to this. I have a CentOS
I looked through other StackOverFlow questions, but I'm a little confused. I'm trying to
I have been looking around online to try to find a complete solution but
I've looked around online as well as in my textbook and this is confusing
This might be a really dumb question, however I've looked around online, etc. And

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.