Difference between abstract class and interface in java ?




Difference between abstract class and interface in java ?

Parameters Abstract class Interface
Description A class which has the abstract keyword
in its declaration is called abstract class.
Abstract classes should have at least one
abstract method. , i.e., methods without a body.
It can have multiple concrete methods.
The interface is a blueprint that can be used to implement a class.The interface does not contain any concrete methods (methods that have code).All the methods of an interface are abstract methods.
Syntax abstract class name
{
     // code
}
interface name
{
     //methods
}
Speed Fast Slow
Multiple
Inheritances
Only one abstract class. Implement several Interfaces.
Structure Abstract & concrete methods. Abstract methods.
When to use To avoid independence. Future enhancement.
Inheritance/
Implementation
The class can inherit only one Abstract Class. A Class can implement multiple interfaces.
Default
Implementation
In case of Abstract Class, you can take
advantage of the default implementation.
While adding new stuff to the interface, it is a nightmare to find all the implementers and implement newly defined stuff.
Data fields The class can have data fields. The interface cannot contain data fields.
Implementation An abstract class can give complete,
default code which should be overridden.
An interface is abstract so that it can't
provide any code.
Use of Access
modifiers
You can use an abstract class which
contains access modifiers.
You cannot use access modifiers for the
method, properties, etc.
Limit of
Extensions
It can extend only one class or one
abstract class at a time.
It can extend any number of interfaces
Class type An abstract class has protected and
public abstract methods.
An interface can have only public
abstract methods.

Related Searches to Difference between abstract class and interface in java ?