Search code examples
javaclassinterfaceextendsimplements

Class implements Interface that extends another Interface


I want to implement an interface in my class that extends from another interface, but I get the follow error:

Class1 is not abstract and does not override abstract method method2(param1,param2) in Interface2

public class Class1 implements Interface1 {       
    public Class1() {
        //some init
    }

    @Override
    public Object method1(Object param1) {
        //some code
    }

    @Override
    public void method2(Object param1, Object param2) {
        //some code
    }         
}

public interface Interface1 extends Interface2 {       
     //some specific code
}

public interface Interface2 {
    public Object method1(Object param1);
    public void method2(Object param1, Object param2);
}

Why doesn't it work and what do I have to do, to make it work?


Solution

  • provide the type for the parameters param1 and param2 try this

      public class Class1 implements Interface1 {       
        public Class1() {
            //some init
        }
    
        @Override
        public Object method1(String param1) {
            //some code
            return null;
        }
    
        @Override
        public void method2(String param1,String param2) {
            //some code
        }         
    }
    
    
     interface Interface1 extends Interface2 {       
         //some specific code
    }
    
    
     interface Interface2 {
        public Object method1(String param1);
        public void method2(String param1,String param2);
    }