Code with an Interface
/* FileName : cat SampleInterface.java */
public interface SampleInterface
{
public void draw();
public void color();
}
Code with and abstract method
/* FileName : SampleAbstractMethod.java */
abstract class SampleAbstractMethod
{
public abstract void draw();
public abstract void color();
}
In what ways are they both different ?
Well surely there has to be a big difference, Java developers would not have brought in interfaces if abstract methods was sufficient. Things that I see in common are
Both cannot have definitions, like the code I have posted.
Inheriting or the implementing class will have to bring in the definition.
Now as far I see it abstract methods can do what interfaces can, then why have interfaces ?, What is so special about an interface that a abstract method cant do ? For what exact reason need and interface ?
EDIT : My question is about the difference between abstract methods and interfaces, NOT abstract classes
which the duplicate links point me to. So please explain how my question is similar to the marked duplicates.