0

Let's see. I have to make a homework with a complicated UML diagramm. I have an interface called Q, and a class called W, which realizes the Q interface. I have another class called R, which extends from W.

The question is: Does the class R realize the Q interface?

Thank you guys!

adamszkly
  • 31
  • 3

3 Answers3

3

1) Implementing an interface (Q) is a contract stating that your class contains certain methods. 2) When you make a subclass (R), all methods from the super class (W) are inherited by the subclass. 3) So..what do you think?

yts
  • 1,890
  • 1
  • 14
  • 24
3

If you have an interface Q

interface Q {
  void say();
}

and a class W which implements Q,

class W implements Q {
  public void say() {
    System.out.println("Hello");
  }
}

and a class R which extends W

class R extends W {
}

Then yes, R also implements Q. You could potentially say,

Q q = new R();
q.say();
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
0

If you're asking: "Does each subclass have to re-implement the interface?" the answer is no. If the superclass implements the interface, the only reason to re-implement it in a subclass is if you need the subclass to do it differently than the superclass.