If Canine has a
beFriendly and
play method then you have no problem; Dog needs an implementation of both functions (as it implements
Pet) and due to it extending
Canine it has an implementation of each. If you implement it as you suggest above it won't make any difference though, as
Dog implements both functions and so the implementations in
Dog will be used.
But here, look at this example:
- public class Canine {
-
public void beFriendly() {
-
System.out.println("I'm friendly");
-
}
-
-
public void play() {
-
System.out.println("I'm playing");
-
}
-
}
- public class Dog extends Canine implements Pet {
-
-
public static void main(String[] args) {
-
Dog dog = new Dog();
-
dog.beFriendly();
-
dog.play();
-
dog.roam();
-
dog.eat();
-
}
-
-
public void roam() {
-
System.out.println("I'm roaming");
-
}
-
-
public void eat() {
-
System.out.println("I'm eating");
-
}
-
}
This will print the text:
- I'm friendly
-
I'm playing
-
I'm roaming
-
I'm eating
Also, functions defined in interfaces are automatically abstract, so you don't have to put the
abstract modifier into an interface.