the major differences between Java Interface and Abstract Class:
- An interface can be used to achieve multiple inheritances and loose coupling which we can’t able to achieve by the abstract class.
- Interface used to achieve complete abstraction whereas an abstract class can achieve partial abstraction.
- An abstract class extends only one normal class or abstract class at a time whereas an interface can extend any number of interfaces at a time.
- An abstract class extends another abstract or normal class whereas an interface can extend only another Java interface.
- In an abstract class, we need to declare methods using “abstract” keyword whereas in the interface we can declare methods with or without the “abstract” keyword.
- An interface can have only abstract methods whereas an abstract class can have both abstract and normal classes.
- An abstract class can have different variables like static, final, non-final, non-static, public, private etc. whereas Interface can have only public, static and final variables.
- An abstract class and its methods can be created by keyword “abstract” whereas interface keyword is used to create interface but not methods.
- An abstract class can have constructors whereas interface doesn’t have a constructor.
- An abstract class is used to define contract, method implementations for subclass whereas an interface is used to define a contract for subclasses.
- An interface can extend only other Java Interfaces whereas an abstract class can extend other class and implement interface also.
- A class that extends an abstract class using extends keyword, needs to implement all methods declared in abstract class unless a class is also an abstract class whereas class which implements the interface using interface keyword also provides an implementation for all methods declared in the interface.