20-CS-694 Advanced Programming Techniques Spring 2012

Interfaces, Exceptions, Graphics, Animation, Threads, Reflection, Networking, RMI, JDBC, JNI

       Previous     Next     All lectures

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

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.io.*;
   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());