Java Scrap Book  

Difference Between Interface and Abstract Class

There are some similarities and differences between an interface and an abstract class that I have arranged in a table for easier comparison

Feature Interface Abstract Class
Multiple Inheritance A class may inherit Several interfaces A class may inherit only one abstract class
Default implementation An Interface cannot provide any code. just the signature. An Abstract class can provide complete, default code and or just the details that have to be overridden
Access Modifiers An Interface cannot have access modifiers for the subs functions, properties etc everything is assumed as public An Abstract class can contain access modifiers for the subs functions and properties.
Core Vs Peripheral Interfaces are used to define the peripheral abilities of class. In other words both Human and Vehicle can inherit from a Movable interface An Abstract class defines the core identity of a class and there is used for objects of the same type
Homogeneity If Various implementations only share method signatures then it is better to use interface. If various implementations are of the same kind are use common behavior or status then abstract class is better to use.
Speed Requires more time to find the actual method in the corresponding classes. Fast
Java Interview Question