Why can't an abstract class extend an interface?

Praveen Reddy Katta picture Praveen Reddy Katta · Aug 9, 2014 · Viewed 17.6k times · Source

I was just wondering why an abstract class can't extend an interface.

Since we can't instantiate an abstract class, can't I just extend the interface and then override those methods in the classes which are extending the abstract class?

For example

abstract class AbstractClass extends InterfaceA 
{

}

interface InterfaceA
{
   public void methodToBeImplemented();
}

class MyClass extends AbstractClass
{
  @Override
  public void methodToBeImplemented(){
      //do something
  }
}  

Answer

Because you don't extends an interface - you implements it.

interface InterfaceA
{
   public void methodToBeImplemented();
}

abstract class AbstractClass implements InterfaceA 
{

}

class MyClass extends AbstractClass
{
  @Override
  public void methodToBeImplemented(){
      //do something
  }
}  

An abstract class is still a class, just like any other. Only interfaces can extends other interfaces.