Register now or log in to join your professional community.
An interface is a contract: the guy writing the interface says, "hey, I accept things looking that way", and the guy using the interface says "Ok, the class I write looks that way".
An interface is an empty shell, there are only the signatures of the methods, which implies that the methods do not have a body. The interface can't do anything. It's just a pattern
Abstract classes, unlike interfaces, are classes. They are more expensive to use because there is a look-up to do when you inherit from them.
Abstract classes look a lot like interfaces, but they have something more : you can define a behavior for them. It's more about a guy saying, "these classes should look like that, and they have that in common, so fill in the blanks!".
For more calrifications, please visit this topic.
Interface is not a class unlike Abstract classes and can implement multiple interfaces. You are basically defining an empty entity which has definition of methods but no body. All methods are by default "public" and you can't define static methods.
Abstract classes may have methods predefined in it or just the details that have to be overridden. A class inherit only one abstract class
Take an example of an abstract class "Mammal" which has "Eat()", "Walk()", "FoodChart()" as methods. Now we know that all mammals eat and walk so why not predefine these methods? But mammals need not necessarily to have same foodchart so let the child class to override this method.
These are the major differences.
we can say they are doing the same functionality both of them are working like a blue print for class design and functions and the class which extends or implements that class inherit the functionality and also i can say that the interface is the solution for language single inheritance which means that the class can extend only one class so to overcome that problem we use the interface to be able to implement more features for the class
in interface all method are by default abstract but abstract class can have implemented method , a java class can implement multiple interface but can extend only one abstract class variables in interface are by default final
abstract classes may have implemantations for some of its member functions but interface can't have any implementation for its member.
abstract class can have access modifier but interface can't have
a class can only extend one abstract class but implement many interfaces at the same time