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?