Prabhu R
Prabhu R

Reputation: 14222

Is the implements clause also inheritable?

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?

Upvotes: 3

Views: 154

Answers (4)

Andreas Dolk
Andreas Dolk

Reputation: 114807

Absolutely. That exactly how it works.

Upvotes: 1

Gordon
Gordon

Reputation: 4843

Yes, B both extends A and implements Runnable.

Upvotes: 1

unorsk
unorsk

Reputation: 9429

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

Upvotes: 0

Erkan Haspulat
Erkan Haspulat

Reputation: 12562

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

Upvotes: 5

Related Questions