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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:46:00+00:00 2026-06-12T16:46:00+00:00

I always thought that two interfaces with the same method cannot be inherited by

  • 0

I always thought that two interfaces with the same method cannot be inherited by one class, as stated in many so questions.

Java jre 7, jdk 1.7

But this code here is working.

Example:

Interfaces:

public interface IObject
{
    public Object create(Object object) throws ExceptionInherit;
}

public interface IGeneric<T>
{
    public T create(T t) throws ExceptionSuper;
}

Implementing class:

public class Test implements IGeneric<Object>, IObject
{
    @Override
    public Object create(final Object object) throws ExceptionInherit
    {
        return object;
    }
}

Don’t those two method declarations have the same body?

Exceptions:

The exceptions are just additive to this construct making it more complex.

public class ExceptionSuper extends Exception {}
public class ExceptionInherit extends ExceptionSuper {}

It works without any thrown exceptions too.

Further: If both methods interfaces throw different inheriting exceptions i could cast UserLogic to any of the two interfaces and retrieve a different subset of the exceptions!

Why is this working?

Edit:

The generic implementation is not even necessary:

public interface IA
{
    public void print(String arg);
}

public interface IB
{
    public void print(String arg);
}

public class Test implements IA, IB
{
    @Override
    public void print(String arg);
    {
        // print arg
    }
}
  • 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-12T16:46:02+00:00Added an answer on June 12, 2026 at 4:46 pm

    You can definitely “implement” two interfaces that have methods of the same signatures. You get into trouble trying to “extend” two classes that have identical method implementations. Multiple-interface inheritance is GOOD; multiple-implementation inheritance is TRICKY.

    An “ExceptionInherit” object can be used in place of an “ExceptionSuper” object because it inherits from it. The “ExceptionInherit” object has all the information that the “ExceptionSuper” object does (plus more). This is not true the other way around. You can’t use an “ExceptionSuper” object in place of “ExceptionInherit” object because the “ExceptionInherit” code expects more than your base object has (well, potentially but not in your case).

    Your implementation of the “create” method fills the ICreateUser “create” signature because it throws an “ExceptionInherit” which can be thrown to catchers of both “ExceptionInherit” and “ExceptionSuper” get all the information they need (just the base class) from the object.

    You couldn’t change your implementation to throw an “ExceptionSuper” because catchers expecting a “ExceptionInherit” would get an object with not enough information.

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

Sidebar

Related Questions

I always thought that a method parameter with a class type is passed as
I have always thought that the .equals() method in java should be overridden to
I always thought that internal class has access to all data in its external
I always thought that && operator in Java is used for verifying whether both
I've always thought that F# had two different ways to pass arguments, curry style
I always thought that you could use OR in a LIKE statment to query
I always thought that if you didn't implement a heartbeat, there was no way
I always thought that parentheses improved readability, but in my textbook there is a
I always thought that when you dropped a control onto an .aspx page that
I always thought that *&p = p = &*p in C. I tried this

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.