I read many links on Stack like this question and i decided to ask .
When i create a Abstract Shape Class in Java i think the Class must have a method to
public abstract class Shape
public abstract double getArea();
public interface Contain
public double getArea();
public abstract class Shape implements Contain
In a round-about way, yes their usages are "similar". More so is the comparison between an abstract class and an
An interface is a set of predefined method stubs that can be implemented within a class and overridden as seen fit without inheritance.
An abstract class is a class with defined values and methods that cannot be instantiated and is for the purpose of inheriting/extending without other non-abstract classes.
For instance, you could have an abstract class called
Animals with methods that are fully written and defined with variables and data members as well, yet you must first extend this
Animals class with, say...
Lion class that is not abstract to be able to instantiate and use these methods and data members.
interfaces, I'll use an example of a radio. You could have an interface called
RadioSystem that has method stubs for changing frequencies, switching from FM to AM and vice versa, etc., which is then implemented into another class, say...
CarRadio so that it already has all of the methods stubs and predefined functionalities defined, then as the programmer you just need to write these methods in a way that best suits the class they're implemented by.