I recently began to wonder, why would I ever use an abstract class, when i could just do an interface with the exact same functionality. Consider the following:
abstract class abstractClass {
public int a;
public void printText(String str) {
System.out.println(str);
}
}
If I had a subclass extending this, I would be sure to have an integer a and a method named printText.
interface Interface{
public int a = 0;
public default void printtext(String str) {
System.out.println(str);
}
}
If I had a class implement this, I would be sure to have an integer a and a method printText.
So, the only difference I see is that with the interface, any class I create would be able to implement as many other interfaces as I would like, but with the extension of the abstract class, I would not be allowed to extend more classes. Why would I ever go for the abstract class? I hope this question isn't too broad, although I can see why some would consider it that.