Need to implement an interface method if it is inherited from a super class?

Prev      Next

Answer: No

Check out the following code. Method vA() in class B satisfies the interface I requirement of class D. The result printed is d.vA:12.

   import java.util.*;

   interface I { int vA(); }

   class A implements I {
      int a;

      A(int x) { a = x; }
      public int vA()  { return a; }
   class B extends A {
      B(int x)  { super (x+1); }
      public int vA()  { return super.vA(); }

   class D extends B implements I {  D(int x) { super(x+1); } }

   public class PG {
      public static void main (String argv[]) {
         D d = new D(10);
         System.out.println("\td.vA:" + d.vA());