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

  • Home
  • SEARCH
  • 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 6765405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:42:28+00:00 2026-05-26T14:42:28+00:00

Let’s take a glance at the following code in Java. interface FirstInaterface { public

  • 0

Let’s take a glance at the following code in Java.

interface FirstInaterface
{
    public void show();
}

interface SecondInterface extends FirstInaterface
{
    @Override
    public void show();

    public void someConcreteMethod();
}

interface ThirdInterface extends SecondInterface
{
    @Override
    public void show();
}

final class Demo implements ThirdInterface
{
    @Override
    public void show()
    {
        System.out.println("The show() method invoked");
    }

    @Override
    public void someConcreteMethod()
    {
        System.out.println("The someConcreteMethod() method invoked");
    }

}

final public class Main
{
    public static void main(String[] args)
    {
        Demo demo=new Demo();
        demo.show();
        demo.someConcreteMethod();
    }
}

The above code in Java shows a multilevel inheritance of interfaces in which ThirdInterface has two interfaces above it. The show() method is firstly being overridden in the interface SecondInaterface ahd then again in the interface ThirdInterface and this interface is finally being inherited by the class Demo.


In such a scenario, which version of the show() methods from the above interfaces will be incorporated by the class Demo? How is the compiler able to resolve a specific version of the show() method dynamically at run time?


I feel that the show() method in the last interface in the above interface inheritance hierarchy (namely ThirdInterface) will be invoked by the compiler. If it is so then, the show() methods in the above two interfaces (namely, FirstInaterface, SecondInaterface) are useless and serve no purpose at all, since they are declared within interfaces, they themselves can never have their own implementations anywhere. When such kind of interface inheritance is useful?

  • 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-26T14:42:29+00:00Added an answer on May 26, 2026 at 2:42 pm

    Only method implementations can override, not method specifications in an interface.

    In such a scenario, which version of the show() methods from the above interfaces will be incorporated by the class Demo? How is the compiler able to resolve a specific version of the show() method dynamically at run time?

    What “versions”? The method signatures are identical, so there is really only one method specification. At runtime, there will be an implementation class, and only the method implementation in that class is what gets actually called.

    If it is so then, the show() methods in the above two interfaces (namely, FirstInaterface, SecondInaterface) are useless and serve no purpose at all, since they are declared within interfaces, they themselves can never have their own implementations anywhere.

    Um, what about classes that implement FirstInterface directly? If anything, what serves no (technical) purpose is “overriding” methods in child interfaces. If SecondInterface and ThirdInterface did not have a show() method, it would have exactly the same syntactical effect.

    However, there can be a valid reason to override methods in a child interface: to provide a different comment explaining semantic changes in the method contract. Examples for this can be seen in the collections framework of the Java API: Set.add() has a different contract than Collection.add(), since it adds the restriction that duplicate elements should not be added.

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

Sidebar

Related Questions

Let's consider the following 3 code lines: struct stat buffer; status = lstat(file.c_str(), &buffer);
Let's say I have the following code: Sub TestRangeLoop() Dim rng As Range Set
Let's say I have the following function in C#: void ProcessResults() { using (FormProgress
Let's say I have the following within my source code, and I want to
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I have a class like this: public class Person { private String
Let's say I have this: public DefaultListModel model = new DefaultListModel(); how do i
Let say I have the following desire, to simplify the IConvertible's to allow me
Let us assume I have two classes: class Base{}; class Derived: public Base{}; none
Let me know the best way to serialize my Java object Download. This is

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.