views:

53

answers:

4

When a class implements an interface, do the subclasses inherit the implemented interfaces too? For example

class A implements Runnable
{
   public void run()
   {
     // do something
   }
}

class B extends A
{
   public static void main(String[] args)
   {
       new Thread(new B()).start(); //works
   }
}

does this mean the implements clause also gets inherited?

+4  A: 

Class A IS-A Runnable, and class B IS-A A, so class B IS-A RUNNABLE. Yes, they do.

Erkan Haspulat
Put another way: The Is-A relation is transitive :-)
Joey
A: 

Sure. B is also Runnable due to B's parent (A) is Runnable.

Andrew Dashin
+1  A: 

Yes, B both extends A and implements Runnable.

Gordon
A: 

Absolutely. That exactly how it works.

Andreas_D