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
}
}
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.