1
import java.io.*;
import java.util.*;

interface animal{
    void bark();
}

interface reptile{
    void bark();
}

public class Interface implements animal, reptile {  //Type interface must implement abstract method reptile.bark() {
    public void reptile.bark()             // Duplicate method bark(), invalid returntype
        System.out.println("wowwow"); 
    }

    public void animal.bark(){           //Duplicate method bark(), invalid  returntype
        System.out.println("hsss");
    }

}

Above is my code. I have two interfaces with the same functions. My spring tool suite keeps on showing the errors mentioned in the comment statements. How to solve these errors?

Mathias Begert
  • 2,354
  • 1
  • 16
  • 26
  • What makes you think `public void reptile.bark()` is valid syntax? There's nothing like C#'s explicit interface implementation (which is what it looks like you're trying) in Java. (It would also make your post clearer if you would format your code.) – Jon Skeet Jul 03 '15 at 06:05
  • Then how can i implement both the bark methods in same class? – Balaji Muthusamy Jul 03 '15 at 07:02
  • 1
    If you are happy with just one implementation, you can just use `public void bark() { ... }`. But you can't give the two interfaces different implementations. As an aside, it's a good idea to follow naming conventions - and naming a class `Interface` is definitely misleading... – Jon Skeet Jul 03 '15 at 07:15
  • A quick search would've led you to [this](http://stackoverflow.com/questions/17484325/implementing-multiple-interfaces-having-same-method) – Saifuddin Hitawala Jul 10 '15 at 07:15
  • is reptile not an animal? – Zelldon Jul 10 '15 at 07:56

0 Answers0