Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extending an interface to another interface

Tags:

java

interface

Let's say I have 2 interfaces here, Moveable and Walkable (sorry for the bad example, but please if you have a better one kindly post it)

interface Runnable{
    void run();
}

interface Walkable extends Runnable {
    void walk();
}

public class Human implements Walkable {

}

And the interface Walkable is a subclass of Runnable, when the Human class implements the Walkable interface should the Human class provide implementations for void walk() from the interface Walkable and void run() from the interface Runnable? does the interface Walkable inherit the abstract method run() from the interface Runnable?

like image 364
user962206 Avatar asked Dec 21 '22 19:12

user962206


2 Answers

Yes, your Human class will need to implement both the walk() and run() methods.

like image 102
Mike Clark Avatar answered Dec 24 '22 02:12

Mike Clark


should the human class provide implementations for void walk from the interface walkable and void run() from the interface runnable?

Yes , when your Walkable interface extends Runnable it also inherits run method means now if Human class is implementing Walkable interface it has to implement both the methods otherwise it should be abstract.

Implementing an Interface is a contract where Implementing class has to implement all the methods declared in Interface.

does the interface Walkable inherit the abstract method run() from the interface Runnable?

Yes, It is the OOPS Inheritance concept.

like image 29
amicngh Avatar answered Dec 24 '22 01:12

amicngh