"Type B cannot be a superinterface C, a superinterface error must be an interface"

Suppose I got this interface A:

interface A
{
    void doThis();
    String doThat();
}

So, I want some class theses to implement the doThis () method, but not doThat () one:

abstract class B implements A
{
    public void doThis()
    {
        System.out.println("do this and then "+ doThat());
    }

}

abstract class B2 implements A
{
    public void doThis()
    {
        System.out.println(doThat() + "and then do this");
    }
}

The error occurs when you decide to implement the doThat method in a regular class:

public class C implements B
{
    public String doThat()
    {
        return "do that";
    }
}

This class leads me to the above error:

"Type B cannot be a superinterface C, but a superinterface must be an interface"

Could anyone now if this class hierarchy is valid or should I do the opposite?

+5
source share
3 answers

You have to use extends

public class C extends B

implements extends. , : vs extends: ? ? .

+19

B , extends:

public class C extends B {
+4

B "". "extends".

+2

All Articles